从python中的feedparser中解析不同的日期格式? [英] Parsing different date formats from feedparser in python?

查看:308
本文介绍了从python中的feedparser中解析不同的日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 feedparser 获取两个不同RSS源中的条目的日期。

I'm trying to get the dates from entries in two different RSS feeds through feedparser.

这是我正在做的:

import feedparser as fp
reddit = fp.parse("http://www.reddit.com/.rss")
cc = fp.parse("http://contentconsumer.com/feed")
print reddit.entries[0].date
print cc.entries[0].date

他们出来:

2008-10-21T22:23:28.033841+00:00

Wed, 15 Oct 2008 10:06:10 +0000

我想要到达我可以找出哪个更容易。

I want to get to the point where I can find out which is newer easily.

我已经尝试使用Python的datetime模块,并通过feedparser文档进行搜索,但是我无法解决这个问题。任何帮助将不胜感激。

I've tried using the datetime module of Python and searching through the feedparser documentation, but I can't get past this problem. Any help would be much appreciated.

推荐答案

解析日期是RSS feed在野外的痛苦,那就是 feedparser 可以是一个很大的帮助。

Parsing of dates is a pain with RSS feeds in-the-wild, and that's where feedparser can be a big help.

如果您使用 * _解析属性(如 updated_pa​​rsed ), feedparser 将完成工作,并将返回一个9元组Python日期在UTC。

If you use the *_parsed properties (like updated_parsed), feedparser will have done the work and will return a 9-tuple Python date in UTC.

请参阅 http://packages.python.org/feedparser/date-parsing.html 获取更多血缘详情。

See http://packages.python.org/feedparser/date-parsing.html for more gory details.

这篇关于从python中的feedparser中解析不同的日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆