简体   繁体   English

使用硒2和python处理browsermobproxy中的har文件

[英]handling har files in browsermobproxy with selenium 2 and python

I am using browsermobproxy to store xhr requests with selenium webdriver and python. 我正在使用browsermobproxy使用硒webdriver和python存储xhr请求。

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. 阅读har文件后,我发现entries为空字典。 Do I have to explicitly write data in the har file? 我是否必须在har文件中显式写入数据? If yes, then how? 如果是,那怎么办? I wrote this in the end of my python file so as to write everything in the har file. 我在python文件的末尾写了这个,以便将所有内容都写在har文件中。 But am I missing some step in between where explicit modification in the har file is to be made using proxy? 但是,在使用代理在har文件中进行显式修改的过程之间,我是否缺少一些步骤?

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

This is what my har file looks like: 这是我的har文件的样子:

 "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"
    }

write the HAR contents to an object 将HAR内容写入对象

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. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM