不能在HAR中获得响应体,在Python中获得Browsermobproxy + selenium + FireFox

时间:2018-04-14 14:16:53

标签: python browsermob-proxy

from selenium import web driver
from browsermobproxy import Server
from selenium.webdriver.common.by import By
import json
import time


server = Server(r'D:\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat')
server.start()
proxy = server.create_proxy({'captureHeaders': True, 'captureContent': True, 'captureBinaryContent': True})
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)

proxy.new_har('xxx')
driver.get('XXX')
proxy.wait_for_traffic_to_stop(1, 60)

这就是我得到的:

enter image description here

我想得到身体的回复但是失败了,我需要设置任何参数吗?

1 个答案:

答案 0 :(得分:1)

我已经花了一些时间来寻找解决这个问题的方法。

将captureHeaders和其他选项从create_proxy()调用移至new_har()。 像这样:

from selenium import web driver
from browsermobproxy import Server
from selenium.webdriver.common.by import By
import json
import time


server = Server(r'D:\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat')
server.start()
proxy = server.create_proxy()
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)

proxy.new_har('xxx', options={'captureHeaders': True, 'captureContent': True, 'captureBinaryContent': True})
driver.get('XXX')
proxy.wait_for_traffic_to_stop(1, 60)