Python3.4找不到urllib2
问题:在Python3.4中 运行如下代码报错,找不到urllib2
import urllib2 response = urllib2.urlopen("http://www.baidu.com/") print response.read()
解决办法:
import urllib.request resp=urllib.request.urlopen("http://www.baidu.com") html=resp.read() print(html)
在python3.4里面,用urllib.request代替urllib2,另外python3之后,不能再用
print html
这样的方式,因为print这个时候已经是一个方法了。必须使用下面的方法
print(html)
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。