13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/browsermob/cli/har_parser.rb', line 13
def parse_har_file
archive = nil
begin
archive = JSON.parse File.read(@harfile)
rescue => err
puts "could not pase archive file: #{err}"
exit 1
end
entries = archive['log']['entries']
hosts = entries.map do |entry|
Addressable::URI.parse(entry['request']['url']).host
end
output = hosts.uniq.map do |host|
urls = entries.map do |entry|
next unless entry['request']['url'].match("http://#{host}/")
{
entry['request']['url'] => entry['timings']
}
end
urls.reject!(&:nil?)
{ host => urls }
end
data = File.open("/tmp/traffic.yml", 'w')
data << output.to_yaml
end
|