undetected-chromedriver 无法使用正确版本的 Chromedriver

undetected-chromedriver isn't being able to use the correct version of chromedriver

提问人:vince 提问时间:8/21/2023 更新时间:9/12/2023 访问量:772

问:

我正在尝试使用 undetected-chromedriver 从 Mac 登录 google 帐户。但是,当我运行下面的代码时,我收到以下错误消息:“消息:未知错误:无法连接到 127.0.0.1:49806 的 chrome from session not created:此版本的 ChromeDriver 仅支持 Chrome 版本 114 当前浏览器版本为 116.0.5845.96”

from undetected_chromedriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By


options = ChromeOptions()
options.add_argument('--headless') 

with Chrome(options=options) as driver:
    driver.get("https://www.youtube.com/") 


我已经从这个网站文本下载了最新版本的 chromedriver,并且我已将 chromedriver 放在与我的脚本相同的文件夹中,但它仍然说我的 chromedriver 已过时。我不知道该怎么办,我在想也许是因为最新版本的 undetected-chromedriver 还不支持 chrome 116.0.5845.96...?

python webautomation undetected-chromedriver

评论

0赞 Shawn 8/21/2023
检查这个答案 - stackoverflow.com/a/76928119/7598774
0赞 vince 8/25/2023
@Shawn非常感谢!您建议的链接的第二个解决方案效果很好!

答:

0赞 Marvin 8/21/2023 #1

尝试将 chromedriver 作为服务对象传递

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

chromeOptions = webdriver.ChromeOptions()
chromedriver_path=Service("ENTER LATEST CHROMEDRIVER PATH HERE")
driver = webdriver.Chrome(service=chromedriver_path, options=chromeOptions)  
driver.get("https://www.youtube.com/")

此外,请通过检查您的 chrome 设置来确保您的 Chrome 版本和 Chromedriver 版本相同,并且您已经为您的系统下载了正确的 chromedriver。

评论

0赞 vince 8/22/2023
嘿马文,谢谢你的帮助!但我想知道,这是否也适用于未检测到的 chromedriver?
0赞 Mukund 8/21/2023 #2
  1. 如果没有任何效果,请删除 /usr/bin/ 中当前存在的 chrome 驱动程序二进制文件。
  2. 之后,chrome 驱动程序所在的位置应为空。删除 chrome 驱动程序的任何其他二进制文件(如果存在)。
  3. 现在只需尝试运行任何简单的硒测试,最新的 chrome 驱动程序就会自动下载。

评论

0赞 vince 8/22/2023
嘿 Mukund,我尝试了您的建议,但仍然遇到同样的错误。我开始相信原因可能是 undetected-chromedriver 与我的 Chrome 版本(即 116.0.5845.96)不兼容,因为当我使用“driver = webdriver”时。Chrome()“而不是”driver = uc.Chrome()“我的代码有效。但是,它没有通过反机器人测试。