chbr
chbr

Reputation: 31

Can`t get response body in HAR, Browsermobproxy + selenium + FireFox in Python

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)

This is all I get:

enter image description here

I want to get the response from the body but failed, are there any arguments I need to set?

Upvotes: 3

Views: 1054

Answers (1)

Gonçalo Redondo
Gonçalo Redondo

Reputation: 31

I've lost some time searching for a solution to this problem.

Move the captureHeaders and other options from the create_proxy() call to new_har(). Like this:

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)

Upvotes: 1

Related Questions