【问题标题】:Selenium-wire does not intercept requests when connecting remotelySelenium-wire 远程连接时不拦截请求
【发布时间】:2021-07-30 09:23:54
【问题描述】:

我在专用计算机上使用 Selenoid 来运行浏览器。
连接如下:

from seleniumwire import webdriver

chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument('disable-infobars')
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_experimental_option('prefs', prefs)
capabilities = {
    "browserName": "chrome",
    "selenoid:options": {
        "enableVNC": True
    }
}
capabilities.update(chrome_options.to_capabilities())

driver = webdriver.Remote(
    command_executor='http://<remote_ip>:4444/wd/hub',
    desired_capabilities=capabilities,
    seleniumwire_options={
        'auto_config': False,
        'addr': '0.0.0.0'
    }
)

连接正常,浏览器控制也可以,但是当我想获取请求列表时,它是空的:

driver.get('https://google.com')
print(driver.requests)

# []

【问题讨论】:

    标签: python-3.x selenium selenoid seleniumwire


    【解决方案1】:

    试试下面的补丁:

    # Go to the Google home page
    driver.get('https://www.google.com')
    
    # Access requests via the `requests` attribute
    for request in driver.requests:
        if request.response:
            print(
                request.url,
                request.response.status_code,
                request.response.headers['Content-Type']
            )
    

    你应该得到类似这样的结果:

    https://www.google.com/ 200 text/html; charset=UTF-8
    https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png 200 image/png
    https://consent.google.com/status?continue=https://www.google.com&pc=s&timestamp=1531511954&gl=GB 204 text/html; charset=utf-8
    https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 200 image/png
    https://ssl.gstatic.com/gb/images/i2_2ec824b0.png 200 image/png
    https://www.google.com/gen_204?s=webaft&t=aft&atyp=csi&ei=kgRJW7DBONKTlwTK77wQ&rt=wsrt.366,aft.58,prt.58 204 text/html; charset=UTF-8
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      相关资源
      最近更新 更多