Pycham(Python3.7)中找不到urllib2和urllib.urlopen 报错问题

Python3.7中找不到urllib2的问题和urllib.urlopen 报错问题

在以前了解了urllib2在python3后已经合并在urllib中了,具体为urllib.response,urllib.requespython

import urllib2
web = urllib2.urlopen('https://www.baidu.com')
f = web.read()
print(f)

报错
在这里插入图片描述
解决方案:Python3里的urllib模块已经发生改变,此处的urllib都应该改为urllib.request。web

更改后的代码svg

import urllib.request
web = urllib.request.urlopen('https://www.baidu.com')
f = web.read()
print(f)

结果显示:
在这里插入图片描述
运行成功url

真~好玩code