Skip to content

Instantly share code, notes, and snippets.

@syndicut
Created February 4, 2012 23:40
Show Gist options
  • Save syndicut/1741141 to your computer and use it in GitHub Desktop.
Save syndicut/1741141 to your computer and use it in GitHub Desktop.
HAR format parser
#!/usr/bin/env python
import json
import sys
har = open(sys.argv[1])
parsed = json.load(har)
parsed['request']['url'] = '/'+'/'.join(parsed['request']['url'].split('/')[3:])
response = '%(method)s %(url)s %(httpVersion)s\r\n' % parsed['request']
for header in parsed['request']['headers']:
response += '%(name)s: %(value)s\r\n' % header
response += '\r\n'
for key, value in parsed['request']['postData'].iteritems():
response += '%s: %s\r\n' % (key, value)
print '%d\n%s' % (len(response), response)
print 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment