python 3.3.2报错:No module named 'urllib2'


ModuleNotFoundError: No module named 'urllib3'

1. ImportError: No module named 'cookielib'1

Python3中,改成 import  http.cookiejar,然后方法里也改成 http.cookiejar,查找替换就行

 

2. NameError: name 'raw_input' is not defined
在版本3中已经用input()替换


3. Import error: No module name urllib
from urllib.request import urlopen


4. ImportError: No module named urllib2
Python 3中urllib2用urllib.request替代

在Python官方文档里面已有说明:

Note
The urllib2 module has been split across several modules in Python 3.0 named urllib.request and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to 3.0.
from urllib.request import urlopen
response = urlopen("http://www.google.com")
html = response.read()
print(html)
sample:
import urllib.request
resp=urllib.request.urlopen('http://www.baidu.com')
html=resp.read()
print(html)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM