簡體   English   中英

通過 Selenium 和 Python 使用代理的 ChromeDriver 日志中的錯誤

[英]Errors in ChromeDriver logs using a proxy through Selenium and Python

我正在嘗試測試如何在 python 中使用 selenium 使用代理這是我正在嘗試的代碼

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

PROXY = "164.68.123.119:9300"
opts = Options()
#opts.add_argument('--proxy-server=%s' % PROXY)
driver = webdriver.Chrome(executable_path="D:/Webdrivers/chromedriver.exe", options=opts)

print(type(driver))
driver.get("https://www.google.com")
myPageTitle=driver.title
print(myPageTitle)
assert "Google" in myPageTitle
time.sleep(10)
print(driver.quit)
driver.quit()

在不依賴代理的情況下運行代碼時,我得到了這樣的錯誤日志

DevTools listening on ws://127.0.0.1:1056/devtools/browser/3bd3f85f-6d2c-4273-87be-a2e108c07626
<class 'selenium.webdriver.chrome.webdriver.WebDriver'>
Google
[10116:7976:1029/180608.508: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.
[10116:7976:1029/180608.509:ERROR:chrome_browser_main_extra_parts_metrics.cc(233)] crbug.com/1216328: Checking Bluetooth availability ended.
[10116:10692:1029/180608.527:ERROR:device_event_log_impl.cc(214)] [18:06:08.528] Bluetooth: bluetooth_adapter_winrt.cc:1073 Getting Default Adapter failed.
[10116:7976:1029/180608.527: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.
[10116:7976:1029/180608.561:ERROR:chrome_browser_main_extra_parts_metrics.cc(240)] crbug.com/1216328: Checking default browser status ended.
[10116:10692:1029/180608.589:ERROR:usb_descriptors.cc(114)] Failed to parse configuration descriptor.
[10116:10692:1029/180608.725:ERROR:usb_descriptors.cc(100)] Failed to read all configuration descriptors. Expected 1, got 0.
[10116:10692:1029/180608.725:ERROR:device_event_log_impl.cc(214)] [18:06:08.726] USB: usb_device_win.cc:93 Failed to read descriptors from \\?\usb#vid_0000&pid_3825#5&50adea6&0&1#{a5dcbf10-6530-11d2-901f-00c04fb951ed}.
<bound method WebDriver.quit of <selenium.webdriver.chrome.webdriver.WebDriver (session="9dde593ef8cb9492d05b49ea42fc0d9f")>>

知道如何修復此類錯誤嗎?

要使用代理啟動 Chrome 瀏覽器,您可以嘗試以下解決方案:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

PROXY = "164.68.123.119:9300"
options = Options()
options.add_argument('--proxy-server={}'.format(PROXY))
options.add_argument("start-maximized")
driver = webdriver.Chrome(executable_path=r'C:\WebDriver\ChromeDriver\chromedriver.exe', options=options)
print(type(driver))
driver.get("https://www.google.com")
myPageTitle=driver.title
print(myPageTitle)
assert "Google" in myPageTitle
time.sleep(10)
driver.quit()

PS: chrome_browser_main_extra_parts_metrics.ccdevice_event_log_impl.ccusb_descriptors.cc等是由於 Chrome/ChromeDriver 兼容性導致的通用錯誤的結果,您現在可以忽略。 有關詳細信息,請檢查 參數化測試由於在啟動時記錄昂貴的指標超時而不穩定


參考

您可以在以下位置找到相關討論:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM