#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

相关文章:

  • 2021-10-10
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
  • 2021-08-23
相关资源
相似解决方案