Python 带selenium的Browsermob代理生成空输出
我正在使用selenium 3.0.2和browsermob proxy 0.7.1来捕获网络数据。我得到的只是一个空的JSON。我的代码是:Python 带selenium的Browsermob代理生成空输出,python,selenium,selenium-webdriver,browsermob,browsermob-proxy,Python,Selenium,Selenium Webdriver,Browsermob,Browsermob Proxy,我正在使用selenium 3.0.2和browsermob proxy 0.7.1来捕获网络数据。我得到的只是一个空的JSON。我的代码是: 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.Fire
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)
我得到的只是这个空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'},
'注释':''}}
你试过换衣服吗 这: 为此:
server = Server("/Users/dev/Downloads/browsermob-proxy-2.1.2/bin/browsermob-proxy.bat")
您需要将文件扩展名(.bat)包含在BrowserMob服务器路径的末尾,以使其正常工作:)我怀疑这是由相同的原因造成的:GeckoDriver目前不支持ChromeDriver和旧FirefoxDriver支持的“代理”所需功能 在GeckoDriver/Marionette更新之前,您可以通过直接在Firefox配置文件上设置代理值来解决此问题。配置文件上的相关代理字段包括:
- network.proxy.http
- network.proxy.http_端口
- network.proxy.ssl
- network.proxy.ssl\u端口
- network.proxy.type(设置为1,“手动”)
BrowserMob代理提供了一个示例,演示了如何在Java中实现这一点。将其转换为Python等价物应该很容易,因为您已经有了firefox_profile对象。1.Browser mob 0.7.1不支持SSL拦截https站点。
2.从您的问题中,我发现您提供了https URL,请尝试使用browsermob 2.1.2及更高版本
3.在要拦截网络的设备中安装SSL证书(SSL证书可在下载的browsermob proxy.zip文件中找到)。
4.如果问题没有解决,请通知我,我将深入调查导致问题的其他因素。我在最近更改代码时预计会出现同样的问题。 尝试将代理添加到配置文件中,而不是webdriver本身。它已经被弃用了,但对我有用
profile.set_proxy(proxy.selenium_proxy())
browser = webdriver.Firefox(firefox_profile=profile)
尝试此命令可能会解决您的问题: yum安装-y谷歌浏览器稳定
我也想知道这个问题的答案!我认为HAR是空的,因为代理实际上没有被使用。对于http(而不是https)站点,我可以使用:
profile.set\u proxy(proxy.selenium\u proxy())
来代替传入代理对象,但set\u proxy
方法已被弃用。。。对于HTTPS,我认为这个问题也很重要:页面是否在浏览器中成功加载?因为您得到的HAR为空,这意味着代理已启动,但代理未看到任何请求。
profile.set_proxy(proxy.selenium_proxy())
browser = webdriver.Firefox(firefox_profile=profile)