欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python3报错:No module named 'urllib2'

程序员文章站 2022-05-28 22:26:41
...

Python 3.3之后,urllib2改为urllib.response


Python 2.7 代码:

import urllib2  
response = urllib2.urlopen('http://www.baidu.com/')  
html = response.read()  
print html   


Python 3.3+ 代码应该为:

import urllib.request
response=urllib.request.urlopen('http://www.baidu.com')
html=response.read()
print(html)



(资料来自SegmentFault)