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.
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)
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)
