【Python】去除Warning:You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored.

今天执行一爬虫脚本时出现以下Warning:

C:hypy>python myblogSummary.py
C:UsersufoAppDataLocalProgramsPythonPython37libsite-packagess4__init__.py:223: 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.")

出现以上告警原因是因为有了这一句:

soup= BeautifulSoup(html.text,'html.parser',from_encoding="utf-8");

解决方案:

将上一句修改成:

soup= BeautifulSoup(html.text,'html.parser');

原因:

python3 缺省的编码是unicode, 再在from_encoding设置为utf8就重复了, 会被忽视掉,故而运行程序出现告警(当然不理这个告警也可以)。

END

原文地址:https://www.cnblogs.com/heyang78/p/15315931.html