简体   繁体   English

feedparser中是否可以从Feed URL中仅检索X个条目?

[英]Is there a way in feedparser to retrieve only X number of entries from a feed URL?

I need to fetch the last 3 feeds from a feed url and display. 我需要从Feed网址和显示中获取最后3个Feed。 The code that i'm currently using is : 我当前正在使用的代码是:

import feedparser

feedUrl = ""

feed = feedparser.parse( feedUrl )

length = len(feed['entries']) 
stop =  (length-4) if length > 3 else -1

for i in range(length-1, stop, -1):
    print feed['items'][i]['title'] + " " + feed['items'][i]['link']

Is there a way using ETags and/or Last-Modified headers to accomplish this? 有没有一种方法可以使用ETag和/或Last-Modified标头来完成此任务?

Unfortunately, no, I don't think there is any feed publisher which uses HTTP level features (like Etags or Last-Modified) inside the feed themselves. 不幸的是,不,我认为没有任何提要发布者本身在提要中使用HTTP级功能(例如Etags或Last-Modified)。 In theory that would work, but since that would probably not be standard in any way and not implemented by everyone, you'll probably end up having to create a fallback mechanism anyway. 从理论上讲这是可行的,但是由于这可能不是任何标准,也不是每个人都可以实施的,因此无论如何您最终都必须创建一个后备机制。

The only similar solution I can think of is using a service like Superfeedr which has a retrieve feature usable with both a before and after query string to get entries published before or after a given entry. 我能想到的唯一类似的解决方案是使用Superfeedr之类的服务,该服务具有可与beforeafter查询字符串一起使用的retrieve功能,以获取在给定条目之前或之后发布的条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM