Selenium-wire 在远程连接时不拦截请求
Selenium-wire does not intercept requests when connecting remotely
我在 运行 浏览器的专用计算机上使用 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)
# []
尝试以下补丁:
# 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
...
我在 运行 浏览器的专用计算机上使用 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)
# []
尝试以下补丁:
# 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
...