I know. Forgot my towel on 25th. This is an attempt to apologize :). A medium snippet (or a little program, if you prefear) to dig through the Galactic Guide.
Update: Another good Guide: http://www.vogon.com/guide/
Update: Following jepri's advice, topic can come from command-line.
#!/usr/bin/perl use strict; use LWP::Simple; use HTML::Parser; my $in_article_body = 0; my $colin = HTML::Parser->new( start_h => [sub { my $self = shift; my ($tagname, $attr) = @_; if ($tagname eq "div" && $attr->{class} eq 'article') { $in_article_body = 1;; } }, "self, tagname, attr"], end_h => [sub { my $self = shift; my ($tagname) = @_; if ($tagname eq "div" && $in_article_body) { $in_article_body = 0; } }, "self, tagname"], text_h => [sub { my $self = shift; my ($origtext) = @_; print $origtext if $in_article_body; }, "self, text"]); my $topic = $ARGV[0] || 'perl'; my $url = "http://www.galactic-guide.com/cgi-bin/articlesearch.cgi?sea +rchval=$topic"; my $string = get( $url ); # It works like Google's "I'm feeling lucky"-mode if ($string =~ /1\. <a href="([^"]*)/ ) { my $new_url = "http://www.galactic-guide.com$1"; my $text = get( $new_url ); $colin->parse( $text ); } else { print "There aren't pages about $topic\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: No panic! (Hitch hikers' facility)
by jepri (Parson) on May 29, 2001 at 10:00 UTC |
Back to
Cool Uses for Perl