Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Writing a simple RSS feed 'grabber' with XML::Parser. (detailed review)

by demerphq (Chancellor)
on Oct 20, 2004 at 18:40 UTC ( [id://400949]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://400949]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-26 04:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found