Good day Bros. I am having an odd problem with a script I wrote to collect and aggregate RSS feeds from local news stations. Here is the script:
#!/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";
When I run this, some of the sources return results and some do not, in random fashion on different days. When they don't, I get status_line responses of either 500 Can't connect or 500 Server closed connection without sending any data back.

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

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.