Import error: No module name urllib2

后端 未结 9 1108
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 06:42

Here\'s my code:

import urllib2.request

response = urllib2.urlopen(\"http://www.google.com\")
html = response.read()
print(html)

Any help?

9条回答
  •  不要未来只要你来
    2020-11-22 07:36

    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'))
    

提交回复
热议问题