初试python爬虫,异常问题记录

在Python中,由于未明确指定HTML解析器,系统默认使用了lxml,可能会导致在不同环境中行为差异。BeautifulSoup警告应通过传递参数features=lxml来指定解析器。另外,bs4的安装触发了DEPRECATION警告,因为没有pyproject.toml文件且wheel包未安装。推荐升级setuptools以遵循新的安装行为。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、未明确指定解析器,因此我正在为此系统使用最佳的HTML解析器(“ html.parser”)

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 60 of the file D:/TEST/LeanPython/testSelenium001.py. To get rid of this warning, pass the additional argument 'features="lxml"' to the BeautifulSoup constructor.

  bsobj = BeautifulSoup(driver.page_source)

问题代码
在这里插入图片描述

解决方法
在问题代码出加上 html.parser 解析
在这里插入图片描述

二 、安装bs4失败

DEPRECATION: bs4 is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559

解决方法:
使用:

python -m pip install --upgrade setuptools
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值