import undetected_chromedriver as uc
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import time


# Set up Chrome WebDriver
service = Service()
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage") 
options.add_argument("--profile-directory=Default")
options.add_argument("--user-data-dir=C:\\Users\\athar\\AppData\\Local\\Google\\Chrome\\User Data\\") 

driver = uc.Chrome(service = service, options = options)

driver.get("https://gmail.com/")
time.sleep(10)

# Close the browser
driver.quit()

我只是想在Chrome个人资料中打开Gmail,这样我就不需要每次都登录了,而且可以使用键盘快捷键激活扩展.运行上述脚本时会出现chromeDRIVE版本错误.如何使用正确版本的chromeDriver.我需要下载什么以及需要传递给Web驱动程序功能的驱动程序路径

完全错误:

Traceback (most recent call last):
  File "d:\programming\Python\Freelance\ExtensionAutomation\test.py", line 16, in <module>
    driver = uc.Chrome(service = service, options = options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 466, in __init__
    super(Chrome, self).__init__(
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 56, in __init__
    super().__init__(
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 206, in __init__
    self.start_session(capabilities)
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 724, in start_session
    super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 290, in start_session        
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 345, in execute
    self.error_handler.check_response(response)
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:54613
from session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 116.0.5845.110
Stacktrace:
Backtrace:
        GetHandleVerifier [0x00FDA813+48355]
        (No symbol) [0x00F6C4B1]
        (No symbol) [0x00E75358]
        (No symbol) [0x00E961AC]
        (No symbol) [0x00E906B4]
        (No symbol) [0x00E90491]
        (No symbol) [0x00EC0C55]
        (No symbol) [0x00EC093C]
        (No symbol) [0x00EBA536]
        (No symbol) [0x00E982DC]
        (No symbol) [0x00E993DD]
        GetHandleVerifier [0x0123AABD+2539405]
        GetHandleVerifier [0x0127A78F+2800735]
        GetHandleVerifier [0x0127456C+2775612]
        GetHandleVerifier [0x010651E0+616112]
        (No symbol) [0x00F75F8C]
        (No symbol) [0x00F72328]
        (No symbol) [0x00F7240B]
        (No symbol) [0x00F64FF7]
        BaseThreadInitThunk [0x768D7D59+25]
        RtlInitializeExceptionChain [0x77C6B79B+107]
        RtlClearBits [0x77C6B71F+191]

推荐答案

您的Chrome浏览器更新到了当前不受此方法支持的新版本,您可以try 在此网站上手动下载驱动程序(您应该根据您的PC和您的Chrome版本(在本例中为117)获取Chrome驱动程序):

https://googlechromelabs.github.io/chrome-for-testing/#stable

然后,您只需将Service语句更改为指向该Web驱动程序,如下所示:

service=Service(executable_path=r"path_to_driver\chromedriver.exe")

Python相关问答推荐

单击Python中的复选框后抓取数据

如何匹配3D圆柱体的轴和半径?

pandas DataFrame中类型转换混乱

具有2D功能的Python十六进制图

跟踪我已从数组中 Select 的样本的最有效方法

通过仅导入pandas来在for循环中进行多情节

如何计算列表列行之间的公共元素

Locust请求中的Python和参数

在内部列表上滚动窗口

追溯(最近最后一次调用):文件C:\Users\Diplom/PycharmProject\Yolo01\Roboflow-4.py,第4行,在模块导入roboflow中

2D空间中的反旋算法

如何记录脚本输出

avxspan与pandas period_range

我如何根据前一个连续数字改变一串数字?

SQLAlchemy bindparam在mssql上失败(但在mysql上工作)

为什么在FastAPI中创建与数据库的连接时需要使用生成器?

PYTHON、VLC、RTSP.屏幕截图不起作用

如何删除重复的文字翻拍?

根据客户端是否正在传输响应来更改基于Flask的API的行为

当HTTP 201响应包含 Big Data 的POST请求时,应该是什么?