Hey Everyone!
I'm trying to hack together a little tool to help me parse RSS feeds. Basically, the code I currently have takes a keyword(s) and prints the articles that have that word in the title. Here is the code:
use 5.14.2;
use strict;
use warnings;
use XML::RSSLite;
use LWP::Simple;
my @keywords = qw(approach);
my $URL = 'http://www.theguardian.com/theguardian/mainsection/rss';
my $content = get($URL);
my %result;
parseRSS(\%result, \$content);
my $re = join "|", @keywords;
$re = qr/\b(?:$re)\b/i;
foreach my $item (@{ $result{items} }) {
my $title = $item->{title};
$title =~ s{\s+}{ }; $title =~ s{^\s+}{ }; $title =~ s{\s+$}{ };
if ($title =~ /$re/) {
print "$title\n\t$item->{link}\n\n";
}
}
This gives me the desired effect with one url, but I need to parse ~20 of these and print the articles from all of them.
I attempted to do this by turning $URL into an array (by making it @URL), and changed that variable throughout the code, but that just gave me several errors.
So, my question is, how can I parse multiple RSS feeds in one script and have all of the output formatted the same way into the same file?
-
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.
|