-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_parser.py
More file actions
33 lines (21 loc) · 801 Bytes
/
Copy pathrequest_parser.py
File metadata and controls
33 lines (21 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import abc
import json
from haralyzer import HarParser
def get_http_parser(filepath):
return HttpArchiveParser(filepath)
class RequestParser(abc.ABC):
"""An abstract request parser class"""
def __init__(self, filepath):
self.filepath = filepath
@abc.abstractmethod
def load_requests(self):
pass
class HttpArchiveParser(RequestParser):
"""An implementation of for Http Archive """
def __init__(self, filepath):
super(HttpArchiveParser, self).__init__(filepath)
def load_requests(self):
with open(self.filepath, 'r', encoding='utf-8-sig') as f:
har_parser = HarParser(json.loads(f.read()))
# Need to collect all entries for all pages and return as a single array.
return har_parser.pages[0].entries