AttributeError: module ‘urllib’ has no attribute ‘urlopen’
import urllib
response = urllib.urlopen('http://www.baidu.com')
print(response.read())
问题描述:使用PYTHON写一个访问任意URL的方法,运行报错: AttributeError: module ‘urllib’ has no attribute ‘urlopen’
解决方案:
由于使用PYTHON2.7版本不支持urllib第三方库。
直接把urllib改为:urllib.request即可,如下代码:
import urllib.request
response = urllib.request.urlopen('http://www.baidu.com')
print(response.read())