1. ModuleNotFoundError: No module named 'cookielib'html
Python3中,import cookielib改为 import http.cookiejar,而后方法里cookielib也改为 http.cookiejar。python
2. ModuleNotFoundError: No module named 'urllib2'cookie
Python 3中urllib2用urllib.request替代。ide
在Python官方文档里面已有说明:google
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.url
from urllib.request import urlopencode
response = urlopen("http://www.google.com")htm
html = response.read()blog
print(html)
3. NameError: name 'raw_input' is not defined
Python 3中用input()替换raw_input()
4. UserWarning: You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored.
注意这句:warnings.warn("You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored.") 缘由:python3 缺省的编码是unicode, 再在from_encoding设置为utf8, 会被忽视。
Python 3中soup = BeautifulSoup(html_doc, "html.parser", from_encoding="utf-8")这一句中删除from_encoding="utf-8"