Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi all.

I am cultivating an interest in scraping RSS feeds and the following program is my first real attempt:

#!/usr/bin/perl -w use strict; use XML::Parser; use LWP::Simple; my $feed; open( FH, ">feed.xml") or die "Error: $!\n"; $feed = get("http://rss.news.yahoo.com/rss/science"); print FH $feed; my $parser = new XML::Parser ( Handlers => { Start => \&hdl_start, End => \&hdl_end, Char => \&hdl_char, } ); + $parser->parsefile("feed.xml"); sub hdl_start { my ($p, $ele, %attribs) = @_; $attribs{'string'} = ''; $feed = \%attribs; } sub hdl_end { + my ($p, $ele) = @_; display_feed($feed) if $ele eq 'title'; display_feed($feed) if $ele eq 'link'; } sub hdl_char { my ($p, $str) = @_; no strict 'refs'; $feed->{'string'} .= $str; } sub display_feed { my $attribs = shift; $attribs =~ s/\n//g; print "$attribs->{'string'}\n\n"; }


The last title tag doesn't generate a corresponding link and the following message appears once the feed is displayed:

no element found at line 594, column 12, byte 45056 at C:/Perl/site/lib/XML/Parser.pm line 185

Ideally, the program would display the feed in html formatted links with the title directly above them for easy navigation to the story in question.

I've used XML::RSS before but I decided to experiment with an additional module.

Thanks,
~Katie

In reply to Writing a simple RSS feed 'grabber' with XML::Parser. by DigitalKitty

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found