Import error: No module name urllib2 in python 3

1.1K    Asked by EdythFerrill in Python , Asked on Apr 14, 2021

 Here's my code:

import urllib2.request 

response = urllib2.urlopen("http://www.google.com") 

html = response.read() 

print(html)

Any help?

Answered by Edyth Ferrill

To solve importerror: no module named 'urllib2' efficiently you should follow the below-mentioned code to get rid of import error:-

from urllib.request import urlopen

html = urlopen("http://www.google.com/").read()

print(html)



Your Answer

Interviews

Parent Categories