使用未检测到的 chromedriver 时出现 OSError:[WinError 6]

问题描述 投票:0回答:1

当我的(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

这不会影响脚本的功能,但我更喜欢在控制台中彻底关闭。

python python-3.x selenium-webdriver selenium-chromedriver undetected-chromedriver
1个回答
1
投票

您可以使用 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!')
© www.soinside.com 2019 - 2024. All rights reserved.