Import error: No module name urllib2

后端 未结 9 1103
隐瞒了意图╮
隐瞒了意图╮ 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:32

    Python 3:

    import urllib.request
    
    wp = urllib.request.urlopen("http://google.com")
    pw = wp.read()
    print(pw)
    

    Python 2:

    import urllib
    import sys
    
    wp = urllib.urlopen("http://google.com")
    for line in wp:
        sys.stdout.write(line)
    

    While I have tested both the Codes in respective versions.

提交回复
热议问题