For a project I'm working on, I'm having to write several Perl scripts to run daily to take in RSS feeds from several software related sites. I wrote--or rather, cut and paste together--the following script. It works just fine on several RSS feeds (e.g, MySQL's Perl DBI Forum: http://forums.mysql.com/feed.php?51,type=rss). However, it doesn't work with sites that use Feedburner (e.g., ONlamp.com). There seems to be something different about their feed or XML structure.
I'm able to use the script (Re: Writing a simple RSS feed 'grabber' with XML::Parser.) that demerphq posted to dump the feed. The dump file doesn't look too different from that of other sites. When I run the script below, I get "Found 0 entries". Somehow I'm not quite getting the root node, which from the dump file looks like it shold be //entry. Does anyone have experience in capturing Feedburner's RSS feed? Can anyone tell me where I'm going wrong? Thanks in advance for any useful advice.
#!/usr/bin/perl -w
use strict;
use URI::Escape;
use LWP::Simple qw/get/;
use XML::LibXML;
use XML::XPath;
use XML::XPath::XMLParser;
my $xml_url = 'http://feeds2.feedburner.com/oreilly/perl';
print "Getting RSS from O'Reilly Network - ONlamp.com \n";
my $xml_file = get($xml_url);
my $parser = XML::LibXML->new;
my $source = $parser->parse_string( $xml_file );
print "Getting nodes & counting them \n";
my @entries = $source->find('//entry')->get_nodelist;
my $count_entries = @entries;
print "Found $count_entries entries. \n";
foreach my $entry (@entries){
my $title = $entry->find('title')->string_value;
my $author = $entry->find('author')->string_value;
my $content = $entry->find('content')->string_value;
my $link = $entry->find('link')->string_value;
my $published = $entry->find('published')->string_value;
print "Saving entry for $author in MySQL \n";
&save_to_mysql($title,$author,$content,$link,$published);
}
exit;
-Spenser
That's Spenser, with an "s" like the detective.