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.


In reply to Capturing Feedburner RSS by Spenser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.