Skip to content

Commit

Permalink
change with Mojo
Browse files Browse the repository at this point in the history
  • Loading branch information
gugod committed Apr 27, 2014
1 parent b9b2487 commit 1a4d86b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cliq
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
#!/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;

binmode STDOUT, ":utf8";

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->parse($response->decoded_content);

$dom->find($selector)->each(
sub {
my $el = shift;
my $attrs = $el->attrs;
my $attrs = $el->attr;
print $el->type . ":\n";
for (keys %$attrs) {
print " " . $_ . ": " . $attrs->{$_} . "\n";
Expand All @@ -29,5 +30,3 @@ $dom->find($selector)->each(

print "\n\n";
});


0 comments on commit 1a4d86b

Please sign in to comment.