【问题标题】:Errors in ChromeDriver logs using a proxy through Selenium and Python通过 Selenium 和 Python 使用代理的 ChromeDriver 日志中的错误
【发布时间】:2021-12-14 17:01:16
【问题描述】:

我正在尝试测试如何在 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")>>

知道如何解决此类错误吗?

【问题讨论】:

    标签: python selenium google-chrome proxy selenium-chromedriver


    【解决方案1】:

    要使用 代理 启动 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.cc、device_event_log_impl.cc、usb_descriptors.cc 等是由于 Chrome/您现在可以忽略的 ChromeDriver 兼容性。详情请查看Parametrized tests are flaky due to a timeout in recording expensive metrics on startup。


    参考

    您可以在以下位置找到相关讨论:

    【讨论】:

    • 非常感谢。我最关心控制台中的输出日志(显示错误)。
    • chrome_browser_main_extra_parts_metrics.cc、device_event_log_impl.c、usb_descriptors.cc等是Chrome/ChromeDriver兼容性的一般bug你现在可以忽略。如果您想详细回答其中任何一个问题,请提出一个新问题。
    • 事实上,这是我关于控制台日志中这些错误的问题
    • 添加了更多细节。
    • 事实上,我把所有我能做到的细节都放了。该代码运行没有问题,但至于登录控制台,我收到了错误消息。我该如何解决这些错误,这些错误的原因是什么?如果无法修复此类日志记录错误,有没有办法隐藏它们?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 2022-01-24
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多