Import error: No module name urllib2

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

    NOTE: urllib2 is no longer available in Python 3

    You 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.

    Using :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.

提交回复
热议问题