- ModuleNotFoundError: No module named ‘cookielib’
C:\Users\abc\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/abc/.PyCharmCE2019.3/config/scratches/scratch_1.py
Traceback (most recent call last):
File “C:/Users/abc/.PyCharmCE2019.3/config/scratches/scratch_1.py”, line 3, in
import cookielib
ModuleNotFoundError: No module named ‘cookielib’
Process finished with exit code 1
Python3中,**import cookielib 改成 import http.cookiejar,将所有cookielib **也改成 http.cookiejar
。
- ModuleNotFoundError: 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)
- NameError: name ‘raw_input’ is not defined
Python 3中用**input()替换raw_input() **
- 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” 即 soup = BeautifulSoup(html_doc, “html.parser”)**
出自:https://www.cnblogs.com/Tanwheey/p/10220585.html
本文详细介绍Python3中模块名称变更,如cookielib改为http.cookiejar,urllib2改为urllib.request,以及raw_input变为input等关键信息。同时,提醒开发者注意Python3默认编码为Unicode,避免不必要的警告。
258

被折叠的 条评论
为什么被折叠?



