1

http://portland.beerandblog.com/feed/atom/がめちゃくちゃになっているようです (0.92 および 2.0 の RSS フィードも同様です)。

ユニバーサル フィード パーサー ( http://code.google.com/p/feedparser/source/browse/trunk/feedparser/feedparser.py?spec=svn295&r=295の最新バージョン) では日付が表示されません。

    <title>Beer and Blog Portland</title>
    <atom:link href="http://portland.beerandblog.com/feed/" rel="self" type="application/rss+xml" />
    <link>http://portland.beerandblog.com</link>
    <description>Bloggers helping bloggers over beers in Portland, Oregon</description>
    <pubDate>Fri, 19 Jun 2009 22:54:57 +0000</pubDate>
    <generator>http://wordpress.org/?v=2.7.1</generator>
    <language>en</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
                    <item>
            <title>Widmer is sponsoring our beer for the After Party!!</title>
            <link>http://portland.beerandblog.com/2009/06/19/widmer-is-sponsoring-our-beer-for-the-after-party/</link>
            <comments>http://portland.beerandblog.com/2009/06/19/widmer-is-sponsoring-our-beer-for-the-after-party/#comments</comments>
            <pubDate>Fri, 19 Jun 2009 22:30:35 +0000</pubDate>
            <dc:creator>Justin Kistner</dc:creator>

            <category><![CDATA[beer]]></category>

私はしようとしています

        試す:
            公開済み = e.published_pa​​rsed
        を除外する:
            試す:
                公開済み = e.updated_pa​​rsed
            を除外する:
                公開済み = e.created_pa​​rsed

日付を取得できないため、失敗しています。

合理的な方法で日付を抽出する方法について何か考えはありますか?

ありがとう!

4

2 に答える 2

3

私のために働く:

>>> e = feedparser.parse('http://portland.beerandblog.com/feed/atom/')
>>> e.feed.date
u'2009-06-19T22:54:57Z'
>>> e.feed.date_parsed
(2009, 6, 19, 22, 54, 57, 4, 170, 0)
>>> e.feed.updated_parsed
(2009, 6, 19, 22, 54, 57, 4, 170, 0)

たぶん、代わりe.updated_parsedに探すべき場所を探していますか?e.feed.updated_parsed

于 2009-06-20T23:14:58.600 に答える
1

ネイキッドを使用するexceptと、コードの問題が隠されている可能性があります。AttributeError がチェックすべき特定の例外であると仮定すると (私はフィード パーサーを使用しません)、これを試してください (偶然のしゃれ):

try:
    published = e.published_parsed
except AttributeError:
    try:
        published = e.updated_parsed
    except AttributeError:
        published = e.created_parsed

いずれにせよ、「失敗しています」ではなく、エラーメッセージとトレースバックを表示してください。

編集 私は最新のリリースをダウンロードしました(つまり、svnからではありません)。ドキュメントの例に従って、次の結果を得ました:

C:\feedparser>\python26\python
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import feedparser
>>> d = feedparser.parse('http://portland.beerandblog.com/feed/atom/')
>>> d.entries[0].updated
u'2009-06-19T22:54:57Z'
>>> d.entries[0].updated_parsed
time.struct_time(tm_year=2009, tm_mon=6, tm_mday=19, tm_hour=22, tm_min=54, tm_sec=57, tm_wday=4, tm_yday=170, tm_isdst=0)
>>> d.entries[0].title
u'Widmer is sponsoring our beer for the After Party!!'
>>> d.entries[0].published
u'2009-06-19T22:30:35Z'
>>> d.entries[0].published_parsed
time.struct_time(tm_year=2009, tm_mon=6, tm_mday=19, tm_hour=22, tm_min=30, tm_sec=35, tm_wday=4, tm_yday=170, tm_isdst=0)
>>>

私が言ったように、私は RSS や Atoms などには興味がありませんが、私には非常に簡単に思えます。<pubDate>タグとarpanetスタイルのタイムスタンプをどこから取得しているのかわかりません。生のソースには存在しない AFAICT -- <published>ISO タイムスタンプがあります。

>>> import urllib
>>> guff = urllib.urlopen('http://portland.beerandblog.com/feed/atom/').read()
>>> guff.find('pubDate')
-1
>>> guff.find('published')
1171
>>> guff[1160:1200]
'pdated>\n\t\t<published>2009-06-19T22:30:35'
>>>

「e.published_pa​​rsed」の「e」は何ですか? 上記で行ったように、feedparser にアクセスして全文を表示することを検討してください。

于 2009-06-20T22:36:49.597 に答える