Python3.7中urllib.urlopen 报错问题

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)

结果显示:

 

 运行成功

posted @ 2018-08-29 17:28  Final_static_杨  阅读(6979)  评论(0编辑  收藏  举报