BeautifulSoup库未写明解析器警告

from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com/pages/page1.html")
bsObj = BeautifulSoup(html.read())
print(bsObj.h2)

代码运行之后警告如下:
UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

成都创新互联公司主要为客户提供服务项目涵盖了网页视觉设计、VI标志设计、网络营销推广、网站程序开发、HTML5响应式网站建设公司移动网站建设、微商城、网站托管及企业网站维护、WEB系统开发、域名注册、国内外服务器租用、视频、平面设计、SEO优化排名。设计、前端、后端三个建站步骤的完善服务体系。一人跟踪测试的建站服务标准。已经为社区文化墙行业客户提供了网站维护服务。

The code that caused this warning is on line 4 of the file D:/Python/venv/test8.py. To get rid of this warning, pass the additional argument 'features="lxml"' to the BeautifulSoup constructor.

翻译如下:
用户警告:没有显式指定语法分析器,因此我使用了此系统的最佳可用HTML语法分析器(“lxml”)。这通常不是问题,但是如果您在另一个系统上运行此代码,或者在不同的虚拟环境中运行此代码,它可能会使用不同的解析器并表现出不同的行为。

导致此警告的代码位于文件d:/python/venv/test8.py的第4行。要消除此警告,请将附加参数'features=“lxml”'传递给beautifulsoup构造函数。

解决:指定解析器,一般使用'lxml'

from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com/pages/page1.html")
bsObj = BeautifulSoup(html.read(),'lxml')
print(bsObj.h2)

网站标题:BeautifulSoup库未写明解析器警告
当前路径:https://www.cdcxhl.com/article10/ppisdo.html

成都网站建设公司_创新互联,为您提供动态网站定制开发标签优化ChatGPT企业网站制作网站导航

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设