Skip to content

Commit

Permalink
a tool to query elements out of a single page.
Browse files Browse the repository at this point in the history
  • Loading branch information
gugod committed Feb 13, 2011
1 parent 243a402 commit 2e6d748
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cliq
@@ -0,0 +1,33 @@
#!/usr/bin/env perl
use strict;
use warnings;
use encoding 'utf8';
use LWP::UserAgent;
use Mojo::DOM;

my ($url, $selector) = @ARGV;
die "Usage: $0 url css-selecotr" unless $url && $selector;

my $ua = LWP::UserAgent->new;
my $response = $ua->get($url);

die "Failed to get the URL" unless $response->is_success;
die "The response is not HTML" unless $response->header("Content-Type") =~ m{^text/html\s*(;|$)};

my $dom = Mojo::DOM->new;
$dom->parse($response->content);

$dom->find($selector)->each(
sub {
my $el = shift;
my $attrs = $el->attrs;
print $el->type . ":\n";
for (keys %$attrs) {
print " " . $_ . ": " . $attrs->{$_} . "\n";
}
print " # " . $el->text;

print "\n\n";
});


0 comments on commit 2e6d748

Please sign in to comment.