我正在尝试使用 BrowserMob Proxy与 browsermob-proxy-py在 Python 上。我需要从页面捕获所有请求的 URL。但是我在 HAR 文件中找不到 https 请求。 Selenium 和 BrowserMob Proxy 正在远程机器上运行。
示例代码:
from selenium import webdriver
import browsermobproxy
SELENIUM_EXECUTOR = 'http://<remote_ip>:4444/wd/hub'
SELENIUM_DESIRED_CAPABILITIES = {
'browserName': 'firefox',
'version': '20.0.0',
'javascriptEnabled': True,
}
prox = browsermobproxy.Client('<remote_ip>:8080')
driver = webdriver.Remote(
command_executor=SELENIUM_EXECUTOR,
desired_capabilities=SELENIUM_DESIRED_CAPABILITIES,
proxy=prox)
url_to_get = 'http://google.ru'
prox.new_har()
driver.get(url_to_get)
for ent in prox.har['log']['entries']:
print ent['request']['url']
driver.quit()
prox.close()
此示例返回 5 个 http 请求。
但是如果我将 url_to_get 更改为“https://...”,我将只看到 3 个 http 请求,而没有 https 请求
有谁也知道如何捕获 https header ?
请您参考如下方法:
我不能说 python 部分,但在我们的 java/junit selenium 测试中,我必须为 selenium 指定 http and 和 https 代理。
我相信最新的 (2.39) 版本的 selenium,他们已经弃用了指定 https 代理,而是参数指定了 ssl 代理。
当我们启动浏览器时,我们的 (java) 代码看起来像这样(您必须四处寻找等效的 python - 抱歉!):
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
//Proxy is from the namespace org.openqa.selenium
Proxy proxy = new Proxy();
//10.0.53.132 == our browsermob proxy server
proxy.setHttpProxy("10.0.53.132:8888");
proxy.setSslProxy("10.0.53.132:8888");
capabilities.setCapability(CapabilityType.PROXY,proxy);
this.driverCapabilities = capabilities;
