当我的(Python)Selenium scraper 完成其任务时,我收到此异常,我正在使用未检测到的 chromedriver:
Exception ignored in: <function Chrome.__del__ at 0x00000241A36A6700>
Traceback (most recent call last): File "C:\Users\Desktop\22.12.06 Vehicle Scrapper\v2\venv\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__
self.quit()
File "C:\Users\Desktop\22.12.06 Vehicle Scrapper\v2\venv\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit
time.sleep(0.1)
OSError: [WinError 6] Controlador no válido
这不会影响脚本的功能,但我更喜欢在控制台中彻底关闭。
您可以使用 SeleniumBase 来解决这个问题,它有一个
undetected-chromedriver
模式,具有更好的错误处理和其他改进:
首先
pip install seleniumbase
,然后以 python
作为基本示例运行:
from seleniumbase import SB
with SB(uc=True) as sb:
sb.open("https://nowsecure.nl/#relax")
try:
sb.assert_text("OH YEAH, you passed!", "h1", timeout=8.75)
sb.post_message("Selenium wasn't detected!", duration=2.8)
sb._print("\n Success! Website did not detect Selenium! ")
except Exception:
sb.fail('Selenium was detected!')