root/Web-Scraper/trunk/eg/search-cpan.pl

Revision 2329 (checked in by miyagawa, 13 years ago)

add search-cpan.pl example

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl
2 # search modules on search.cpan.org and extract name, description and author
3
4 use strict;
5 use warnings;
6 use URI;
7 use Web::Scraper;
8 use YAML;
9
10 my $query = shift || "Foo";
11 my $uri   = URI->new("http://search.cpan.org/search");
12 $uri->query_form(query => $query, mode => 'all');
13
14 my $scraper = scraper {
15     process "body#cpansearch>p", 'modules[]' => scraper {
16         process "//a[1]", name => 'TEXT', url => '@href';
17         process "small", description => 'TEXT';
18         process "span.date", date => 'TEXT';
19         process q{//a[starts-with(@href, '/~')][2]}, author => 'TEXT';
20     };
21 };
22
23 warn Dump $scraper->scrape($uri);
Note: See TracBrowser for help on using the browser.