问题
I am using selenium 3.0.2 and browsermob proxy 0.7.1 to capture the network data. All I am getting is an empty JSON. My code is:
server = Server("/Users/dev/Downloads/browsermob-proxy-2.1.2/bin/browsermob-proxy")
server.start()
proxy = server.create_proxy()
if browser is None:
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.privatebrowsing.autostart", True)
browser = webdriver.Firefox(firefox_profile=profile, proxy=proxy.selenium_proxy())
proxy.new_har("google", options={'captureHeaders': True, 'captureContent': True})
browser.get("https://google.com/")
print(proxy.har)
All I get is this empty JSON
{'log': {'pages': [{'id': 'google', 'comment': '', 'pageTimings': {'comment': ''}, 'startedDateTime': '2016-12-01T14:23:24.984-05:00', 'title': 'google'}], 'entries': [], 'version': '1.2', 'creator': {'comment': '', 'name': 'BrowserMob Proxy', 'version': '2.1.2'}, 'comment': ''}}
回答1:
I suspect this is caused by the same GeckoDriver bug/missing feature in this question: GeckoDriver does not currently support the "proxy" desired capability that ChromeDriver and the old FirefoxDriver supported.
Until GeckoDriver/Marionette is updated, you can work around this problem by setting the proxy values on the Firefox Profile directly. The relevant proxy fields on the profile are:
- network.proxy.http
- network.proxy.http_port
- network.proxy.ssl
- network.proxy.ssl_port
- network.proxy.type (set to 1, "manual")
BrowserMob Proxy has a test that shows how to do this in Java. It should be easy to translate that into a Python equivalent, since you already have a firefox_profile object.
回答2:
1.Browser mob 0.7.1 doesn't have SSL support for intercepting https sites.
2. From your question I observed you gave https URL , try using browsermob 2.1.2 and above
3. Install SSL certificates in device In which you want to intercept network(SSL certificates are available in the browsermob proxy .zip file you download ).
4. If issue didn't resolve inform me I will look deep into other things causing issues.
回答3:
I have expected the same issue when I changed my code recently. Try to add the proxy into the profile instead of the webdriver itself. It's deprecated but it works for me.
profile.set_proxy(proxy.selenium_proxy())
browser = webdriver.Firefox(firefox_profile=profile)
回答4:
Try this cmd maybe fix your problem:
yum install -y google-chrome-stable
回答5:
Have you tried changing
This:
server = Server("/Users/dev/Downloads/browsermob-proxy-2.1.2/bin/browsermob-proxy")
To This:
server = Server("/Users/dev/Downloads/browsermob-proxy-2.1.2/bin/browsermob-proxy.bat")
You need to include the file extension (.bat) at the end of your BrowserMob server path for it to work :)
来源:https://stackoverflow.com/questions/40919104/browsermob-proxy-with-selenium-generates-empty-output