Created
February 14, 2018 12:43
-
-
Save slavone/02ef965f4fde4798f0ce79f1c9a17993 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'uri' | |
# how to use: | |
# ruby parse_har_file.rb filename_in_curr_dir pattern_to_match_correct_urls optional_param_accepted_statuses_separated_by_commas | |
filename = ARGV[0] | |
match_pattern = Regexp.compile(ARGV[1] || "") | |
accept_statuses = (ARGV[2] || "").split(',').map(&:to_i) | |
json = JSON.parse File.read(filename) | |
urls = json.dig('log', 'entries') | |
.select { |e| accept_statuses.empty? || accept_statuses.include?(e.dig('response', 'status')) } | |
.map { |e| e.dig 'request', 'url' } | |
.select { |u| u =~ match_pattern } | |
.map { |e| URI.decode e } | |
puts urls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment