def test_match_request_type(har_data): """ Tests the ability of the parser to match a request type. """ # The HarParser does not work without a full har file, but we only want # to test a piece, so this initial load is just so we can get the object # loaded, we don't care about the data in that HAR file. init_data = har_data('humanssuck.net.har') har_parser = HarParser(init_data) entry = har_data('single_entry.har') # TEST THE REGEX FEATURE FIRST # assert har_parser.match_request_type(entry, '.*ET') assert not har_parser.match_request_type(entry, '.*ST') # TEST LITERAL STRING MATCH # assert har_parser.match_request_type(entry, 'GET', regex=False) assert not har_parser.match_request_type(entry, 'POST', regex=False)
def test_match_request_type(har_data): """ Tests the ability of the parser to match a request type. """ # The HarParser does not work without a full har file, but we only want # to test a piece, so this initial load is just so we can get the object # loaded, we don't care about the data in that HAR file. init_data = har_data('humanssuck.net.har') har_parser = HarParser(init_data) entry = har_data('single_entry.har') # TEST THE REGEX FEATURE FIRST # assert har_parser.match_request_type(entry, '.*ET') assert not har_parser.match_request_type(entry, '.*ST') # TEST LITERAL STRING MATCH # assert har_parser.match_request_type(entry, 'GET', regex=False) assert not har_parser.match_request_type(entry, 'POST', regex=False)
import csv from bs4 import BeautifulSoup from haralyzer import HarParser with open('../../Downloads/public.tableau.com_base_6.har', 'r') as f: # with open('../../Downloads/tahir-data/public.tableau.com_two.har', 'r') as f: # with open('../../Downloads/men_baseball/3-harib-mensbaseball.har', 'r') as f: # with open('../../Downloads/men_baseball/13full-harib-mensbaseball.har', 'r') as f: # with open('../../Downloads/soccer/mens_soccer_6.har', 'r') as f: # with open('../../Downloads/soccer/mens_soccer_8.har', 'r') as f: # with open('../../Downloads/soccer/mens_soccer_15.har', 'r') as f: har_parser = HarParser(json.loads(f.read())) tree_list = [] for page in har_parser.pages: for index, entry in enumerate(page.entries): if har_parser.match_request_type(entry, 'POST'): text_str = str(entry.get('response').get('content').get('text')) if text_str.__contains__( 'School Name:') and not text_str.__contains__('518965;'): data = json.loads(text_str.strip()) # data = text_str # import pdb;pdb.set_trace() # data = text_str # data = ast.literal_eval(entry.get('response').get('content').get('text')) print(text_str) cmdResultList = data.get('vqlCmdResponse').get('cmdResultList') print(cmdResultList) for index, i in enumerate(cmdResultList): # try: dict_data = {} # command_items = json.loads(i.get('commandReturn').get('tooltipText')).get('actions').get('commandItems')