Skip to content

Instantly share code, notes, and snippets.

@latk
Created September 17, 2013 15:10
Show Gist options
  • Save latk/6595659 to your computer and use it in GitHub Desktop.
Save latk/6595659 to your computer and use it in GitHub Desktop.
SO: 18826446 helper script http://stackoverflow.com/q/18826446/1521179
use strict; use warnings;
use feature 'say';
use autodie;
use File::Slurp;
use Mojo;
use List::MoreUtils 'uniq';
use Data::Dump qw/dd pp/;
my %urls = (
"local mirror 1" => 'original URL redacted',
"local mirror 2" => 'original URL redacted',
);
for my $file (sort keys %urls) {
my $dom = Mojo::DOM->new(scalar read_file $file);
say "I looked at the source of the page at `$urls{$file}`, and the form has following `<input>`s:";
say "";
for my $input ($dom->find('form input')->each) {
delete @{ $input->attr }{qw/height id class/};
say " * `", $input->to_xml, "`";
}
say "";
say "And the following `<select>` groups:";
say "";
for my $select ($dom->find('form select')->each) {
delete @{$select->attr}{qw/id style width size/};
my $options = pp sort { do{no warnings 'numeric'; $a <=> $b} } grep length(), $select->find('option')->attr("value")->each;
$select->replace_content('');
say " * `", $select->to_xml, "` with values ",
join ", ", map "`$_`", $options;
}
say "";
my @links = uniq map s/^[^?]*//r, grep /poll_data\.pl?/, $dom->find('a')->attr("href")->each;
if (@links) {
say "Additionally, links with the following queries are present:";
say "";
say " * `$_`" for @links;
say "";
say "which means that the script also responds to GET requests";
say "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment