刚开始学习python,不知道原来python 2和python3是有区别的,然后就出现了一系列错误。
错误的
import urllib
response=urllib.urlopen('http://www.zhihu.com')
html=response.read()
print(html)
正确的
import urllib.request
response=urllib.request.urlopen('http://www.zhihu.com')
html=response.read()
print(html)
总结:
运行报错"AttributeError: module 'urllib' has no attribute 'urlopen'
原因:Python3.6中应该用urllib.request。更改后就不会再出现这个错误了