in reply to Slashdot Headline Grabber for Win32
I think the Slashdot Headline Grabber is a good idea. I only have one question: why not using LWP to get the /. xml page? I think it's better, and using LWP it is possible to set up a proxy (very useful if you are beyond a firewall). I hacked your code a bit, and here are my suggestions:
It may also be a good idea to use XML::DOM to parse the XML downloaded from /. but that is probably too much for the Headline Grabber: the for loop is quicker.
Any comment is highly appreciated.
marcos
use LWP; use HTTP::Request::Common; # # .... # sub fetch_headlines { my @D; my $ua = new LWP::UserAgent; return 0 unless ($ua); $ua->proxy('http', 'http://myproxy.mynet.org:8080'); #set up your +proxy here my $url = "http://www.slashdot.org/slashdot.xml"; my $res = $ua->request(GET $url); if ($res->is_success) { @D = split /\n/, $res->content; } else { return 0; } my ($title, $url); for (@D) { $title = $1 if /\<title\>(.*)\<\/title\>/; $url = $1 if /\<url\>(.*)\<\/url\>/; if (/<\/story>/) { $stories{$url} = $title; push(@keys, $url); $title = ""; $url = ""; } } return 1; }
It may also be a good idea to use XML::DOM to parse the XML downloaded from /. but that is probably too much for the Headline Grabber: the for loop is quicker.
Any comment is highly appreciated.
marcos
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE: Slashdot Headline Grabber for Win32
by httptech (Chaplain) on May 04, 2000 at 16:24 UTC | |
by marcos (Scribe) on May 04, 2000 at 16:36 UTC | |
by httptech (Chaplain) on May 04, 2000 at 16:38 UTC | |
RE: RE: Slashdot Headline Grabber for Win32
by GridMonk (Acolyte) on May 09, 2000 at 08:09 UTC | |
by marcos (Scribe) on May 09, 2000 at 21:31 UTC | |
by GridMonk (Acolyte) on May 10, 2000 at 07:02 UTC |
In Section
Code Catacombs