in reply to Re: Writing a simple RSS aggregator.
in thread Writing a simple RSS aggregator.
Here are a couple of other methods that were inspired by Zaxo:
Method #1
#!/usr/bin/perl -w use strict; use LWP::Simple; use CGI qw( :standard ); require 5.8.0; print "Content-type: text/html\n\n"; print start_html; my $RSS = get("http://thraxil.org/rss"); { local $/ = "</item>"; open my $rss, "<", \$RSS or die "Aaiiigh - $!"; while (<$rss>) { my ($title) = m!<title>(.*?)</title>!is; my ($link) = m!<link>(.*?)</link>!is; my ($desc) = m!<description>(.*?)</description>!is; next unless $title && $link && $desc; print "Title: $title\nLink: $link\nDescription: $desc\n\n"; } close $rss; }
Method #2
#!/usr/bin/perl -w use strict; use LWP::Simple; use CGI qw( :standard ); print "Content-type: text/html\n\n"; print start_html; my $RSS = get("http://thraxil.org/rss"); my @items = $RSS =~ m!<item.*?>(.*?)</item>!gis; for (@items) { my ($title) = m!<title>(.*?)</title>!is; my ($link) = m!<link>(.*?)</link>!is; my ($desc) = m!<description>(.*?)</description>!is; next unless $title && $link && $desc; print "Title: $title\nLink: $link\nDescription: $desc\n\n"; }
Each of these has its own merits, but if you want to do it right, use a real parser from CPAN. :-)
|
---|