在python3.3后urllib2已经不能再用,只能用urllib.request来代替
如在python3.3.0中运行一下脚本
import urllib2
html=response.read()
print(html)
提示找不到“urllib2”模块
Traceback (most recent call last):
File "b.py", line 1, in <module>
import urllib2
ImportError: No module named 'urllib2'
将urllib2换为urllib
import urllib
html=response.read()
print(html)
出现
Traceback (most recent call last):
File "b.py", line 2, in <module>
AttributeError: 'module' object has no attribute 'urlopen'
将urllib2给改为urllib.request即可正常运行
import urllib.request
print(urllib.request.__file__)