Import error no urllib2 module

python3代码如下:

import urllib2.request
response = urllib2.urlopen("http://www.baidu.com")
html = response.read()

错误信息:Import error no urllib2 module

原因:在Python 3中,urllib2的几个模块重命名为urllib.request和urllib.error

解决方案:

from urllib.request import urlopen
html = urlopen("http://www.baidu.com/")
print(html)

posted @ 2022-11-13 22:36  dlhl  阅读(17)  评论(0)    收藏  举报