使用 selenium 的 Browsermob 代理生成空输出

Sou*_*Dev 5 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.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)
Run Code Online (Sandbox Code Playgroud)

我得到的只是这个空的 JSON

{'log': {'pages': [{'id': 'google', 'comment': '', 'pageTimings': {'comment': ''}, 'startedDateTime': '2016-12-01T14 :23:24.984-05:00', '标题': 'google'}], '条目': [], '版本': '1.2', '创建者': {'评论': '', '名称' : 'BrowserMob 代理', '版本': '2.1.2'}, '评论': ''}}

dan*_*own 0

你有没有尝试过改变

这:

server = Server("/Users/dev/Downloads/browsermob-proxy-2.1.2/bin/browsermob-proxy") 
Run Code Online (Sandbox Code Playgroud)

对此:

server = Server("/Users/dev/Downloads/browsermob-proxy-2.1.2/bin/browsermob-proxy.bat")
Run Code Online (Sandbox Code Playgroud)

您需要在 BrowserMob 服务器路径末尾包含文件扩展名 (.bat) 才能正常工作:)