BeautifulSoup库没有显式指定解析器的解决办法

错误提示

Warning (from warnings module):
File “C:/Users/ASUS/小牛试刀+bsoup4除标签.py”, line 8
bf = BeautifulSoup(html)
GuessedAtParserWarning: 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.

The code that caused this warning is on line 8 of the file C:/Users/ASUS/小牛试刀+bsoup4除标签.py. To get rid of this warning, pass the additional argument ‘features=“lxml”’ to the BeautifulSoup constructor.

意思是

警告(来自警告模块):

文件“C:/Users/ASUS/小牛试刀+B组4除标签.py”,第8行

bf=BeautifulSoup(html)

GuessedAtParserWarning:没有显式指定解析器,所以我使用了这个系统中可用的最好的HTML解析器(“lxml”)。这通常不是问题,但是如果您在另一个系统上或在不同的虚拟环境中运行此代码,它可能会使用不同的解析器并表现出不同的行为。

导致此警告的代码位于文件C:/Users/ASUS的第8行/小牛试刀+B组4除标签。要消除此警告,请将附加参数’features=“lxml”'传递给BeautifulSoup构造函数。

解决办法

在错误提示的那一行代码中加解析器传递给BeautifulSoup构造函数。
错误代码

bf=BeautifulSoup(html)

正确代码

bf=BeautifulSoup(html,'lxml'
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

eeeasyFan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值