Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

a tool to query elements out of a single page.

  • Loading branch information...
commit 2e6d7486bd3ff1a7318decef023475528a992385 1 parent 243a402
Kang-min Liu authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 cliq
33 cliq
View
@@ -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";
+});
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.