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())