編輯:我剛剛意識到我最近重新安裝了 Chrome,所以這可能是問題所在。
我認為 Selenium 希望在 Appdata 中找到 Chrome,但它并不存在。我嘗試將 C:\Program Files\Google\Chrome\ 中的 Application 檔案夾復制到 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)
我嘗試了上面代碼的變體,但都不起作用。
原問題:
在過去的幾個月里,我的代碼運行良好。然后當我昨天運行它時,下載新的chromedriver后,瀏覽器打開但網頁不加載,它卡在地址“data:,”。
這是一個具有相同問題的簡化版本:
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]
uj5u.com熱心網友回復:
當您之前執行您的程式時 谷歌瀏覽器瀏覽器和ChromeDriver完美同步。因此它執行得很好。
但是目前 Google Chrome 瀏覽器正在更新到版本 95.0.4638.69,您的程式沒有找到匹配的ChromeDriver來驅動 Chrome 瀏覽器。
因此,您會data:,在地址欄中看到。
解決方案
使用key executable_path指向下載的ChromeDriver匹配版本如下:
browser = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
uj5u.com熱心網友回復:
我無法解決它,但發現了一個解決方法:使用 Firefox 和 geckodriver。之前每當 Chrome 更新時,我都會遇到很多問題,所以我希望這次更改會有所改善,因為我只使用 Firefox。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/345563.html
上一篇:Oracle日志 歸檔模式管理
