Is it possible to collect an html source code using python?

1

I would like something in python, some library that could access the site and get its source code (HTML). Example:

Talsite.com
<h1>hello</h1>

Is it possible for python to get into Talsite.com and collect the source code for it? If so, how?

I'm using python 2.7

    
asked by anonymous 12.11.2017 / 14:56

1 answer

2

Python 2:

import urllib
url = "https://pt.stackoverflow.com"
f = urllib.urlopen(url)
print f.read()

Python 3:

import urllib.request
url = "https://pt.stackoverflow.com"
f = urllib.request.urlopen(url)
print(f.read())
    
12.11.2017 / 18:32