python3中urllib2的导入问题:ImportError: No module named 'urllib2'

#import urllib2, urllib
response = urlopen('http://www.baidu.com/')
html = response.read()
print (html)


运行提示 ImportError: No module named 'urllib2'

因为在py3中

urllib2模块已分为Python 3中的几个模块命名urllib.requesturllib.error

2to3将源转换为Python 3时,工具将自动调整导入。这句话啥意思?

改成 :

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

就可以了

参考:https://stackoverflow.com/questions/2792650/import-error-no-module-name-urllib2
posted on 2018-09-19 15:22  现实不似你所见  阅读(5969)  评论(0编辑  收藏  举报