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