Here\'s my code:
import urllib2.request
response = urllib2.urlopen(\"http://www.google.com\")
html = response.read()
print(html)
Any help?
urllib2
is no longer available in Python 3You can try following code.
import urllib.request
res = urllib.request.urlopen('url')
output = res.read()
print(output)
You can get more idea about urllib.request
from this link.
urllib3
import urllib3
http = urllib3.PoolManager()
r = http.request('GET', 'url')
print(r.status)
print( r.headers)
print(r.data)
Also if you want more details about urllib3
. follow this link.
That worked for me in python3:
import urllib.request
htmlfile = urllib.request.urlopen("http://google.com")
htmltext = htmlfile.read()
print(htmltext)
The above didn't work for me in 3.3. Try this instead (YMMV, etc)
import urllib.request
url = "http://www.google.com/"
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
print (response.read().decode('utf-8'))