You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome现有实例下Selenium连接失败问题求助

Selenium无法连接Chrome调试端口问题排查记录

环境信息

  • Ventura 13.4.1
  • Python 3.11.4
  • 运行环境:VSCode的Jupyter Notebook
  • Selenium 4.11.2

问题背景

原本可正常在已有网页运行Selenium脚本,无任何包更新操作的情况下,突然出现报错:WebDriverException: Message: Unable to obtain Selenium Manager。最初通过miniconda安装的Selenium 4.11.2,按相关Bug报告建议改用pip版本后,仍无法连接Chrome。

已执行操作

  1. 通过brew安装ChromeDriver,执行chromedriver --port=9222返回正常启动信息:
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 9222 
ChromeDriver was started successfully.
  1. 执行命令/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222,成功打开新Chrome窗口。
  2. 将ChromeDriver和Google Chrome路径添加到系统PATH:
export PATH=$PATH:/opt/homebrew/Caskroom/chromedriver/114.0.5735.90/chromedriver
export PATH=$PATH:/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

通过echo $PATH确认路径已成功添加:/opt/homebrew/Caskroom/chromedriver/114.0.5735.90/chromedriver:/Applications/Google Chrome.app/Contents/MacOS/Google Chrome

脚本及报错情况

初始脚本

from bs4 import BeautifulSoup
import requests
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import time
import json

chromeoptions = Options()
chromeoptions.debugger_address='127.0.0.1:9222'
driver = webdriver.Chrome(service=Service(ChromeDriverManager(driver_version='114.0.5735.90').install()), options=chromeoptions)

执行后报错:Message: unknown error: cannot connect to chrome at 127.0.0.1:9222 from chrome not reachable

更新后脚本

chromeoptions = Options()
chromeoptions.add_experimental_option(name='debuggerAddress', value='127.0.0.1:9222')
# chromeoptions.debugger_address='127.0.0.1:9222'
driver = webdriver.Chrome(options=chromeoptions)
driver.get("https://www.linkedin.com")

执行后仍出现相同报错。

Selenium Manager调试输出

执行./selenium-manager --browser chrome --debug返回:

DEBUG   Checking chromedriver in PATH
DEBUG   Running command: chromedriver --version
DEBUG   Output: "ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052})"
DEBUG   Running command: which chromedriver
DEBUG   Output: "/opt/homebrew/bin/chromedriver"
DEBUG   Found chromedriver 114.0.5735.90 in PATH: /opt/homebrew/bin/chromedriver
DEBUG   chrome detected at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
DEBUG   Using shell command to find out chrome version
DEBUG   Running command: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
DEBUG   Output: "Google Chrome 114.0.5735.198 "
DEBUG   Detected browser: chrome 114.0.5735.198
DEBUG   Required driver: chromedriver 114.0.5735.90
INFO    Driver path: /opt/homebrew/bin/chromedriver
INFO    Browser path: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

内容的提问来源于stack exchange,提问作者Vijay Tripathi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 00:53:24