import urllib web = urllib.urlopen('https://www.baidu.com') f = web.read() print(f)
报错:
Traceback (most recent call last):
File "D:/coding/python/text.py", line 2, in <module>
web = urllib.urlopen('https://www.baidu.com')
AttributeError: module 'urllib' has no attribute 'urlopen'
Process finished with exit code 1
解决方案:Python3里的urllib模块已经发生改变,此处的urllib都应该改成urllib.request。
更改后的代码
import urllib.request web = urllib.request.urlopen('https://www.baidu.com') f = web.read() print(f)
结果显示:
运行成功