Selenium Python 以前可以工作的代码现在打开浏览器然后卡在 "data:,"。说 "chrome not reachable"
Selenium Python code that used to work now opens browser and then gets stuck in "data:,". Says "chrome not reachable"
编辑:我刚刚意识到我最近重新安装了 Chrome,所以这可能是问题所在。
我认为 Selenium 希望在 Appdata 中找到 Chrome,但它不在那里。我尝试将 C:\Program Files\Google\Chrome\ 中的应用程序文件夹复制到 C:\Users\hougy\AppData\Local\Google\Chrome 但这并没有解决它。
我也试过显示 Chrome 的安装位置,但它也不起作用:
options = webdriver.ChromeOptions()
options.binary_location = 'C:\Program Files\Google\Chrome\Application\chrome.exe'
browser = webdriver.Chrome(options=options)
我尝试了上述代码的变体,其中 none 有效。
原问题:
我的代码在过去几个月里运行良好。然后当我昨天 运行 它在下载新的 chromedriver 后,浏览器打开但网页没有加载,它卡在地址“数据:”。
这是一个有同样问题的简化版本:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from lxml import etree
import csv
import time
from datetime import datetime
import requests
#options = webdriver.ChromeOptions()
#options.add_experimental_option('excludeSwitches', ['enable-logging'])
#options.add_argument('--no-sandbox')
#options.add_argument("start-maximized")
#browser = webdriver.Chrome(options=options)
browser = webdriver.Chrome()
quote = 'https://www.fundamentus.com.br/detalhes.php?papel=BBAS3'
browser.get(quote)
我尝试用上面注释的代码替换 browser = webdriver.Chrome() 因为这里有些人建议这样做,但结果是一样的。唯一的区别是它似乎忽略了一些与蓝牙相关的错误消息,这些错误消息一直存在并且不是问题的原因。
我尝试移动到最新版本的 Python,然后更新 pip 并重新下载所有库。我还更新了 Chrome 并使用最新的稳定版 chromedriver。
我在我的第二台 PC 上尝试了 运行 代码,它可以在相同的 Python、Chrome、chromedriver 和库版本上工作。
这是我 运行 得到的结果:
python .\seleniumTest.py
DevTools listening on ws://192.168.0.104:63785/devtools/browser/5d07327b-ae87-49ee-be00-b9cb0f055b74
[5156:5772:1101/160103.660:ERROR:chrome_browser_main_extra_parts_metrics.cc(230)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no
report that this ends.
[5156:5772:1101/160103.664:ERROR:chrome_browser_main_extra_parts_metrics.cc(233)] crbug.com/1216328: Checking Bluetooth availability ended.
[5156:13960:1101/160103.681:ERROR:device_event_log_impl.cc(214)] [16:01:03.680] Bluetooth: bluetooth_adapter_winrt.cc:1073 Getting Default Adapter failed.
[5156:5772:1101/160103.690:ERROR:chrome_browser_main_extra_parts_metrics.cc(236)] crbug.com/1216328: Checking default browser status started. Please report if there is no
report that this ends.
[5156:5772:1101/160103.714:ERROR:chrome_browser_main_extra_parts_metrics.cc(240)] crbug.com/1216328: Checking default browser status ended.
[5156:13960:1101/160126.589:ERROR:device_event_log_impl.cc(214)] [16:01:26.588] USB: usb_service_win.cc:258 Failed to get device driver name: Element not found. (0x490)
Traceback (most recent call last):
File "C:\Users\hougy\OneDrive\Documentos\plij\seleniumTest.py", line 14, in <module>
browser = webdriver.Chrome()
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
RemoteWebDriver.__init__(
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 266, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 357, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
self.error_handler.check_response(response)
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
Stacktrace:
Backtrace:
Ordinal0 [0x006006F3+2492147]
Ordinal0 [0x00599BD1+2071505]
Ordinal0 [0x004A2340+1057600]
Ordinal0 [0x0049739D+1012637]
Ordinal0 [0x004BFF64+1179492]
Ordinal0 [0x004BC43B+1164347]
Ordinal0 [0x004B9C9F+1154207]
Ordinal0 [0x004E9DFF+1351167]
Ordinal0 [0x004E9A6A+1350250]
Ordinal0 [0x004E568B+1332875]
Ordinal0 [0x004C21D4+1188308]
Ordinal0 [0x004C302F+1191983]
GetHandleVerifier [0x007867A6+1545030]
GetHandleVerifier [0x0083105C+2243580]
GetHandleVerifier [0x0068BC97+518199]
GetHandleVerifier [0x0068AD80+514336]
Ordinal0 [0x0059ED2D+2092333]
Ordinal0 [0x005A2EE8+2109160]
Ordinal0 [0x005A3022+2109474]
Ordinal0 [0x005ACB71+2149233]
BaseThreadInitThunk [0x76736359+25]
RtlGetAppContainerNamedObjectPath [0x773187A4+228]
RtlGetAppContainerNamedObjectPath [0x77318774+180]
当您之前执行程序时,google-chrome browser and the 是完美同步的。因此它执行得很好。
但目前 Google Chrome 浏览器正在更新至 版本 95.0.4638.69 您的程序找不到匹配的 来驱动Chrome 浏览器。
因此您在地址栏中看到 data:,
。
解决方案
使用keyexecutable_path
指向下载的ChromeDriver匹配版本如下:
browser = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
参考资料
您可以在以下位置找到一些相关的详细讨论:
我无法解决它,但发现了一个解决方法:使用 Firefox 和 geckodriver。以前每次 Chrome 更新时我都遇到过很多问题,所以我希望这次更改会有所改善,因为我只使用 Firefox 来做这件事。
我终于在3个月后解决了这个问题。我不认为大多数收到相同错误消息的人都会遇到这种情况,但这是我遇到的情况:
Surfshark VPN 更新了他们的应用程序,最新版本使我的 Selenium 脚本无法找到 geckodriver 和 chromedriver。我一卸载 Surfshark 应用程序,它就立即重新开始工作。仅仅杀死进程是不够的。
我现在通过 OpenVPN 应用程序使用 Surfshark,这个应用程序不会阻止我的脚本运行。 Surfshark 应用程序具有更多功能,但到目前为止我无法同时使用这两种功能。
编辑:我刚刚意识到我最近重新安装了 Chrome,所以这可能是问题所在。
我认为 Selenium 希望在 Appdata 中找到 Chrome,但它不在那里。我尝试将 C:\Program Files\Google\Chrome\ 中的应用程序文件夹复制到 C:\Users\hougy\AppData\Local\Google\Chrome 但这并没有解决它。
我也试过显示 Chrome 的安装位置,但它也不起作用:
options = webdriver.ChromeOptions()
options.binary_location = 'C:\Program Files\Google\Chrome\Application\chrome.exe'
browser = webdriver.Chrome(options=options)
我尝试了上述代码的变体,其中 none 有效。
原问题:
我的代码在过去几个月里运行良好。然后当我昨天 运行 它在下载新的 chromedriver 后,浏览器打开但网页没有加载,它卡在地址“数据:”。
这是一个有同样问题的简化版本:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from lxml import etree
import csv
import time
from datetime import datetime
import requests
#options = webdriver.ChromeOptions()
#options.add_experimental_option('excludeSwitches', ['enable-logging'])
#options.add_argument('--no-sandbox')
#options.add_argument("start-maximized")
#browser = webdriver.Chrome(options=options)
browser = webdriver.Chrome()
quote = 'https://www.fundamentus.com.br/detalhes.php?papel=BBAS3'
browser.get(quote)
我尝试用上面注释的代码替换 browser = webdriver.Chrome() 因为这里有些人建议这样做,但结果是一样的。唯一的区别是它似乎忽略了一些与蓝牙相关的错误消息,这些错误消息一直存在并且不是问题的原因。
我尝试移动到最新版本的 Python,然后更新 pip 并重新下载所有库。我还更新了 Chrome 并使用最新的稳定版 chromedriver。
我在我的第二台 PC 上尝试了 运行 代码,它可以在相同的 Python、Chrome、chromedriver 和库版本上工作。
这是我 运行 得到的结果:
python .\seleniumTest.py
DevTools listening on ws://192.168.0.104:63785/devtools/browser/5d07327b-ae87-49ee-be00-b9cb0f055b74
[5156:5772:1101/160103.660:ERROR:chrome_browser_main_extra_parts_metrics.cc(230)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no
report that this ends.
[5156:5772:1101/160103.664:ERROR:chrome_browser_main_extra_parts_metrics.cc(233)] crbug.com/1216328: Checking Bluetooth availability ended.
[5156:13960:1101/160103.681:ERROR:device_event_log_impl.cc(214)] [16:01:03.680] Bluetooth: bluetooth_adapter_winrt.cc:1073 Getting Default Adapter failed.
[5156:5772:1101/160103.690:ERROR:chrome_browser_main_extra_parts_metrics.cc(236)] crbug.com/1216328: Checking default browser status started. Please report if there is no
report that this ends.
[5156:5772:1101/160103.714:ERROR:chrome_browser_main_extra_parts_metrics.cc(240)] crbug.com/1216328: Checking default browser status ended.
[5156:13960:1101/160126.589:ERROR:device_event_log_impl.cc(214)] [16:01:26.588] USB: usb_service_win.cc:258 Failed to get device driver name: Element not found. (0x490)
Traceback (most recent call last):
File "C:\Users\hougy\OneDrive\Documentos\plij\seleniumTest.py", line 14, in <module>
browser = webdriver.Chrome()
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
RemoteWebDriver.__init__(
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 266, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 357, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
self.error_handler.check_response(response)
File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
Stacktrace:
Backtrace:
Ordinal0 [0x006006F3+2492147]
Ordinal0 [0x00599BD1+2071505]
Ordinal0 [0x004A2340+1057600]
Ordinal0 [0x0049739D+1012637]
Ordinal0 [0x004BFF64+1179492]
Ordinal0 [0x004BC43B+1164347]
Ordinal0 [0x004B9C9F+1154207]
Ordinal0 [0x004E9DFF+1351167]
Ordinal0 [0x004E9A6A+1350250]
Ordinal0 [0x004E568B+1332875]
Ordinal0 [0x004C21D4+1188308]
Ordinal0 [0x004C302F+1191983]
GetHandleVerifier [0x007867A6+1545030]
GetHandleVerifier [0x0083105C+2243580]
GetHandleVerifier [0x0068BC97+518199]
GetHandleVerifier [0x0068AD80+514336]
Ordinal0 [0x0059ED2D+2092333]
Ordinal0 [0x005A2EE8+2109160]
Ordinal0 [0x005A3022+2109474]
Ordinal0 [0x005ACB71+2149233]
BaseThreadInitThunk [0x76736359+25]
RtlGetAppContainerNamedObjectPath [0x773187A4+228]
RtlGetAppContainerNamedObjectPath [0x77318774+180]
当您之前执行程序时,google-chrome browser and the
但目前 Google Chrome 浏览器正在更新至 版本 95.0.4638.69 您的程序找不到匹配的
因此您在地址栏中看到 data:,
。
解决方案
使用keyexecutable_path
指向下载的ChromeDriver匹配版本如下:
browser = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
参考资料
您可以在以下位置找到一些相关的详细讨论:
我无法解决它,但发现了一个解决方法:使用 Firefox 和 geckodriver。以前每次 Chrome 更新时我都遇到过很多问题,所以我希望这次更改会有所改善,因为我只使用 Firefox 来做这件事。
我终于在3个月后解决了这个问题。我不认为大多数收到相同错误消息的人都会遇到这种情况,但这是我遇到的情况:
Surfshark VPN 更新了他们的应用程序,最新版本使我的 Selenium 脚本无法找到 geckodriver 和 chromedriver。我一卸载 Surfshark 应用程序,它就立即重新开始工作。仅仅杀死进程是不够的。
我现在通过 OpenVPN 应用程序使用 Surfshark,这个应用程序不会阻止我的脚本运行。 Surfshark 应用程序具有更多功能,但到目前为止我无法同时使用这两种功能。