In Python 2, use urllib2 which comes with the standard library.Use urllib.request.urlopen()
:
import urllib2urllib.request
response =with urllib2urllib.request.urlopen('http://www.example.com/') as f:
html = responsef.read().decode('utf-8')
This is the most basic way to use the library, minus any error handling. YouYou can also do more complex stuff such as changing headers. The documentation can be found
On Python 2, the method is in here.urllib2
:
import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read()