/ Published in: Perl
Won't work with Google code pages: they are javascript powered.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env perl # # grabcode.pl # Download code between <pre> tags from remote HTML pages # Takes a list of urls as argument use strict; use warnings; use WWW::Mechanize; use HTML::TreeBuilder::XPath; use Encode; my @urls = @ARGV; my $browser = WWW::Mechanize->new; $browser->agent_alias('Linux Mozilla'); #$browser->credentials('uname', 'passwd'); foreach my $url (@urls) { my $page; if ( $browser->get($url)->is_success() ) { $page = $browser->content(); } else { next; } my $tree= HTML::TreeBuilder::XPath->new; $tree->parse( $page ); my $nodes = $tree->findnodes( '//pre'); } }