#!/usr/bin/perl #use strict; $| = 1; use Storable qw(nstore retrieve); use XML::FeedPP; use Date::Manip; use LWP::UserAgent; Date_Init("TZ=MST"); my $feeddate = UnixDate("now","%a, %e %b %Y %H:%M:%S %z"); my @feeds = qw ( http://fox-obfeeds.endplay.com/feeds/rssFeed?obfType=RSS_FEED&siteId=2 +00017 http://www.kpho.com/category/216452/kpho-newstream?clienttype=rss http://www.kpho.com/category/210050/5-investigates?clienttype=rss http://scrippsobfeeds.endplay.com/content-syndication-portlet/feedServ +let?obfType=RSS_FEED&siteId=10008&categoryId=20413 http://scrippsobfeeds.endplay.com/content-syndication-portlet/feedServ +let?obfType=RSS_FEED&siteId=10008&categoryId=20423 http://scrippsobfeeds.endplay.com/content-syndication-portlet/feedServ +let?obfType=RSS_FEED&siteId=10008&categoryId=10001 http://scrippsobfeeds.endplay.com/content-syndication-portlet/feedServ +let?obfType=RSS_FEED&siteId=10008&categoryId=20412 http://scrippsobfeeds.endplay.com/content-syndication-portlet/feedServ +let?obfType=RSS_FEED&siteId=10008&categoryId=20001 http://www.phoenixnewtimes.com/index.rss ); my $dryheat = XML::FeedPP::RSS->new(); $dryheat->title("Dryheat Phoenix News"); $dryheat->description("Aggregated News from Various Phoenix Sources"); $dryheat->pubDate($feeddate); my $ua = LWP::UserAgent->new(); my $ctr = 0; print "Getting feeds.\n"; foreach my $f (@feeds) { $ctr++; my $response = $ua->get($f); if ($response->is_success) { my $feed; eval {$feed = XML::FeedPP->new($response->content, -type => 's +tring'); }; if ($feed) { $dryheat->merge($feed); } print "\tOK $f\n"; } else { print "\tResponse failed: $f ",$response->status_line,"\n"; } } $dryheat->normalize(); open(OUT,">dryheat-rss.htm") or die "Can't open output: $!"; print OUT '<html><head><link rel="stylesheet" type="text/css" href="dr +yheat.css"><title>Dryheat Phoenix Local News</title></head><body>'; foreach my $item (@{$dryheat->{rss}->{channel}->{item}}) { my $category = $item->{category}; if (ref($category) eq 'HASH') { $category = $category->{'#text'}; my $foo = 'bar'; } elsif (ref($category) eq 'ARRAY') { my $foo = 'bar'; $category = $category->[0]->{'#text'}; } unless ($category) { $category = 'News'; } my $link = $item->{link}; my $description = $item->{description}; $description =~ s/\<\/?p\>//; if ($description !~ /SL Advert/) { my $title = $item->{title}; my $media; if ($item->{'media:content'}) { eval {$media = $item->{'media:content'}->{'-url'}}; } my $source = $item->{source}->{'#text'}; my $date = UnixDate(ParseDate($item->{pubDate}),'%A %i:%m %p') +; print OUT '<div class="item-content">'; if ($media) { print OUT "<img class=\"pic\" src=\"$media\">"; } my @header; if ($category) { push(@header,$category); } push (@header,$date); if ($source) { push(@header,"\($source\)"); } print OUT '<p class="header">',join(" - ",@header),"</p>\n"; print OUT "<p class=\"link\"><a href=\"$link\">$title</a></p>\ +n"; print OUT "<p class=\"desc\">$description</p></div>\n"; } } print OUT '</body></html>'; close OUT; print "Done.\n";
The odd thing is that when I put the feed URLs into a browser right after running the script, they invariably return results. I suppose it's possible that these sources are blocking crawlers somehow, but I don't know why anyplace would do that with an RSS feed. Also this doesn't explain why they would work sometimes and not other times.
Anyone know what could be going on here or how I can debug?
In reply to Odd problem accessing RSS feeds by cormanaz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |