0

I am using browsermobproxy to store xhr requests with selenium webdriver and python.

proxy.new_har("req", options={'captureHeaders': True,'captureContent':True})
driver.get("http://www.example.com")
proxy.har

After reading the har file, I find entries to be null dictionary. Do I have to explicitly write data in the har file? If yes, then how? I wrote this in the end of my python file so as to write everything in the har file. But am I missing some step in between where explicit modification in the har file is to be made using proxy?

har_data = json.dumps(proxy.har, indent=4)
save_har = open("req.har", 'a')

This is what my har file looks like:

 "log": {
    "comment": "", 
    "entries": [], 
    "version": "1.2", 
    "pages": [
        {
            "pageTimings": {
                "comment": ""
            }, 
            "comment": "", 
            "title": "requirements", 
            "id": "requirements", 
            "startedDateTime": "2016-01-08T11:48:01.477+05:30"
        }
    ], 
    "creator": {
        "comment": "", 
        "version": "2.1.0-beta-4-littleproxy", 
        "name": "BrowserMob Proxy"
    }
proprius
  • 422
  • 6
  • 16

1 Answers1

0

write the HAR contents to an object

result = json.dumps(self.proxy.har, ensure_ascii=False)

write the results to a file

har_file = open('newfile' + '.har', 'w')
har_file.write(str(result))
har_file.close()

This works for me.

Prakash Palnati
  • 2,416
  • 16
  • 32
  • this will work if you have the correct har data, which then depends on the location where har data write has been initiated. – proprius Aug 21 '16 at 15:04