2

我正在尝试在 Python 上将BrowserMob 代理browsermob-proxy-py一起使用。我需要从页面捕获所有请求的 URL。但我在 HAR 文件中找不到 https 请求。Selenium 和 BrowserMob 代理正在远程机器上运行。

示例代码:

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 标头?

4

1 回答 1

2

I can't speak to the python piece, but in our java/junit selenium tests, I had to specify both an http and and https proxy for selenium.

I believe the newest (2.39) version of selenium, they've deprecated specifying an https proxy, instead the parameter specifies an ssl proxy.

Our (java) code looks something like this when we spin up the browser (you'll have to poke around to find the equivalent python - sorry!):

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;
于 2014-01-06T17:10:54.537 回答