Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse HAR file to extract text content?

Tags:

python

har

I saved my network data in a har file. Now I want to extract the whole dictionary of content that contains specific word as an indicator to save that dictionary to an array. There are multiple similar dicts in the har file that contain that value and I want to create an array of all the responses.

I am fairly new to python(and coding in general), explainlikeimfive kind explanation will greatly help me.

like image 422
alias micheal Avatar asked Jan 27 '26 00:01

alias micheal


1 Answers

You can use haralyzer module. You can install it easily using pip like so:

pip install haralyzer

The following code uses this sample har file:

>>> import json
>>> from haralyzer import HarParser, HarPage
>>>
>>> with open('sample.har', 'r', encoding='utf-8') as f:
...     har_parser = HarParser(json.loads(f.read()))
>>>
>>> data = har_parser.har_data
>>> type(data)
<class 'dict'>
>>>
>>> data.keys()
dict_keys(['version', 'creator', 'pages', 'entries'])
>>>
>>> har_parser.har_data["pages"]
[{'startedDateTime': '2013-08-24T20:16:16.997Z', 'id': 'page_1', 'title': 'http://ericduran.github.io/chromeHAR/', 'pageTimings': {'onContentLoad': 317, 'onLoad': 406}}]

For more info, check the official GitHub repository.

like image 192
Anwarvic Avatar answered Jan 28 '26 16:01

Anwarvic