开发者

Reddit RSS feed returning less items when requested through HTTP?

开发者 https://www.devze.com 2022-12-13 19:07 出处:网络
I am trying to read data from an RSS feed which has 25 items. When I request the RSS file through HTTP it says there are only 20 items.

I am trying to read data from an RSS feed which has 25 items. When I request the RSS file through HTTP it says there are only 20 items.

function test($location)
{
    $doc = new DomDocument();
    $doc->load($location);
    $items = $doc->getElementsByTagName('item');
    return $items->length开发者_如何学Go;
}

// Prints 20
echo test('http://www.reddit.com/r/programming/new/.rss?after=t3_');

// Prints 25
echo test('programming.xml');

I've tried RSS feeds from other subreddits as well with the same result.


I see what the issue is now... If you visit a sub-reddit like /r/programming/ and go to the "new" tab to see newest submissions, there are two sorting options. The first option is "rising" which only shows up-and-coming entries, the alternate sort order is "new".

Since I chose the "new" sort order in my browser it saved a cookie and was used as the default sort order afterwards. However, accessing the page through code was still using the default sort order, which returned a variable amount of results.

I resolved the issue by appending the sort order query string to the request url: http://www.reddit.com/r/programming/new/.rss?sort=new


If it were having problems loading the feed, it'd probably issue a warning of some sort.

Right now, your sample code for the reddit feed shows that it has 14 items. The number of items in that feed is not constant. So the issue is that your local copy is different that the one you were loading from reddit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号