【发布时间】:2017-04-16 14:10:38
【问题描述】:
我正在使用 selenium 3.0.2 和 browsermob 代理 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.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', “标题”:“谷歌”}],“条目”:[],“版本”:“1.2”,“创作者”: {'comment': '', 'name': 'BrowserMob 代理', 'version': '2.1.2'}, '评论':''}}
【问题讨论】:
-
我也很想知道这个问题的答案!我认为 HAR 是空的,因为实际上并未使用代理。对于 http(而不是 https)站点,我可以通过使用:
profile.set_proxy(proxy.selenium_proxy())代替传递代理对象来使代码工作,但不推荐使用set_proxy方法......对于 HTTPS,我认为这个问题是也相关:bugzilla.mozilla.org/show_bug.cgi?id=1103196 -
页面在浏览器中加载成功了吗?由于您得到一个空的 HAR,这意味着代理已启动,但代理尚未看到任何请求。
标签: python selenium selenium-webdriver browsermob browsermob-proxy