Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Don't panic! (Hitch hikers' facility)

by larsen (Parson)
on May 29, 2001 at 00:33 UTC ( [id://83785]=CUFP: print w/replies, xml ) Need Help??

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
    That's a nice program. I was confused for a while because no matter what I typed in at the command line, it printed out the geek code. For a moment I thought that was the joke.

    A line like $topic = $ARGV[0] ? shift @ARGV : 'perl'; would give it nice command line functionality. Then I could include it in shell scripts and the like :)

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://83785]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-28 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found