Python 3.x Selenium wire在远程连接时不拦截请求
我在专用计算机上使用Selenoid来运行浏览器。Python 3.x Selenium wire在远程连接时不拦截请求,python-3.x,selenium,selenoid,seleniumwire,Python 3.x,Selenium,Selenoid,Seleniumwire,我在专用计算机上使用Selenoid来运行浏览器。 连接方式如下: 从seleniumwire导入webdriver chrome\u options=webdriver.ChromeOptions() chrome_选项。添加_参数('disable-infobar')) chrome_选项。添加_参数('--disable extensions') chrome_选项。添加_参数('--no sandbox') chrome_选项。添加_参数(“--忽略证书错误”) chrome_选项。添加
连接方式如下:
从seleniumwire导入webdriver
chrome\u options=webdriver.ChromeOptions()
chrome_选项。添加_参数('disable-infobar'))
chrome_选项。添加_参数('--disable extensions')
chrome_选项。添加_参数('--no sandbox')
chrome_选项。添加_参数(“--忽略证书错误”)
chrome_选项。添加_实验_选项('prefs',prefs)
能力={
“浏览器名”:“chrome”,
“硒:选项”:{
“enableVNC”:True
}
}
更新(chrome\u options.to\u capabilities())
driver=webdriver.Remote(
命令_executor='http://:4444/wd/hub',
期望的能力=能力,
seleniumwire_选项={
“自动配置”:False,
“地址”:“0.0.0.0”
}
)
连接正常,浏览器控件也可以工作,但当我想要获取请求列表时,它是空的:
driver.get('https://google.com')
打印(驱动程序请求)
# []
尝试以下修补程序:
# 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×tamp=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
...