LWP, RSS, and Feeds[ See LWP and RSS code in action: rss.cgi ]First, in class tonight we talked about using LWP::Simple. You should make sure this module is installed on your computer. This module has a subroutine called get() that goes out on the internet and fetches the document you specify with a URL:
use LWP::Simple;
my $html = get('http://www.washington.edu');
Next, we talked about RSS, which is an XML format that allows websites to publish their content in a standard format, without all the presentation code (the HTML). You can add content to your site from other websites by reading in their RSS feed. wikipedia RSS page Note that there is another feed format called Atom. For the purpose of keeping the Perl assignments on track, I'll just use RSS in this class. However, you're free to incorporate Atom feeds into your code too. wikipedia Atom page To read (and create) RSS feeds, use the XML::RSS Perl module. You will probably need to install this module on your machine. It works like this:
# first, go out on the internet and get the RSS/XML data.
# we use LWP::Simple's get() subroutine to do this.
my $xml_data = get($xml_path);
# next create an XML::RSS object to parse the data, and parse the data
my $rss = XML::RSS->new;
$rss->parse($xml_data);
# now print the title, link, and description of each RSS item
foreach my $item (@{$rss->{'items'}}) {
print qq{
Link is: $item->{'link'}
Title is: $item->{'title'}
Description is: $item->{'description'}
};
}
A small list of RSS feeds you can use | ||
|
UW Extension Perl Programming Course Three, Perl, the Web, and Databases March 26 - June 04, 2007 (note no class May 28) Monday evenings 10 Sessions, 6:00 to 9:00 PM Instructor: Joel Grow (joelg at u.washington.edu) |
links: perl.com cpan perldoc online learn.perl.org perlmonks.org seattle perl users group (spug) |
|
|
Thursday, May 24, 2012 you're number: 824 | ||