2010-04-12 32 views
0

什麼我嘗試做:只使用PHP腳本獲取新的RSS條目?

取X個號碼的RSS從我的博客供稿和回聲只有條目。我的問題是,如何知道哪些項目已經解析?

解決方案迄今:

取飼料每5小時,所有標題存儲的數據庫表或平面文件中。接下來運行檢查標題是否已經存在於數據庫中,如果不打印並保存在數據庫中。

但我不知道這是否是最好的做法呢?

如果有人知道一個快速的方式,這將是偉大的。對不起,我英文很差。

回答

3

如果你正在解析的博客條目有一些日期指示器,只需要一個名爲CREATE的DATETIME類型的字段你的數據庫並在那裏保存這個日期值。然後,當您解析時選擇最新的DATETIME SELECT MAX(CREATED) FROM posts LIMIT 1,並且不要插入任何早於該日期的日期。

如果您希望某些博客延遲更新其rs,但將過去的日期保留爲其時間戳,則此解決方案可能存在輕微缺陷。

1

我認爲你應該存儲你提取的最後一篇文章的日期。當你下次獲取時,你只能收集那些比你存儲的日期更新的那些...

+0

由於不同的格式有不同的存儲機制,ID也非常危險,這一切都取決於他準確讀什麼。 – 2010-04-12 07:44:38

1

閱讀文檔我認爲,通常的做法是關閉的RSS提要的GUID元的工作。這有時是源文章的URI,有時是數字,有時是傳統的GUID。

使用此元素來查看您是否已收到文章會否定解析日期的需要,這就是Google Reader通常如何確定是否已收集了某個項目。

<?xml version="1.0" encoding="UTF-8"?> 
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
<channel> 
    <atom:link href="http://www.stevefenton.co.uk/RSS/Blog/" rel="self" type="application/rss+xml" /> 
    <title>Steve Fenton Blog</title> 
    <link>http://www.stevefenton.co.uk/RSS/Blog/</link> 
    <description>Blog</description> 
    <language>en</language> 
    <copyright>Copyright 2008 - 2010 Steve Fenton</copyright> 
    <category>Blog</category> 
    <generator>Swift Point Content Management System</generator> 
    <ttl>60</ttl> 
    <managingEditor>[email protected] (Site Admin)</managingEditor> 
    <item> 
     <title><![CDATA[Jquery Plugin Infinite Scroller With AJAX]]></title> 
     <link>http://www.stevefenton.co.uk/Content/Blog/Date/201004/Blog/Jquery-Plugin-Infinite-Scroller-With-AJAX/</link> 
     <description><![CDATA[Friday, 9th April 2010 - Jquery Plugin Infinite Scroller With AJAX <p>I have just finished a new plugin for the jQuery framework.</p><p>The jQuery Infinite Scroller is a great way to deliver a really long list of things, in smaller chunks. For example, if you were displaying articles you could load a page with the first 10 results, then dynamically add more results to the bottom of the list when people start scrolling down. The further they scroll, the more articles you add - thus making it theoretically infinite.</p><p>When the plugin detects that no more results are available, it stops trying to get more items to add.]]> &lt;a href="http://www.stevefenton.co.uk/Content/Blog/Date/201004/Blog/Jquery-Plugin-Infinite-Scroller-With-AJAX"&gt;View Details&lt;/a&gt;.</description> 
     <guid>http://www.stevefenton.co.uk/Content/Blog/Date/201004/Blog/Jquery-Plugin-Infinite-Scroller-With-AJAX</guid> 
    </item> 
    <item> 
     <title><![CDATA[Auto Load Your PHP Classes]]></title> 
     <link>http://www.stevefenton.co.uk/Content/Blog/Date/201004/Blog/Auto-Load-Your-PHP-Classes/</link> 
     <description><![CDATA[Wednesday, 7th April 2010 - Auto Load Your PHP Classes <p>In PHP5 you can create classes to organise your code and represent objects that you want to pass around. This has long been a feature of other languages and was a fundamentally important step forward for PHP.</p><p>There was one thing, though, that I didn't like about PHP classes. If I wanted to instantiate a new "Customer" or "Product", I had to make sure that I included the PHP file that contained the "Customer" or "Product" class. This meant doing this:</p><p>[[#CODE:php:<br>include_once 'classes/Customer.php';</p>]]> &lt;a href="http://www.stevefenton.co.uk/Content/Blog/Date/201004/Blog/Auto-Load-Your-PHP-Classes"&gt;View Details&lt;/a&gt;.</description> 
     <guid>http://www.stevefenton.co.uk/Content/Blog/Date/201004/Blog/Auto-Load-Your-PHP-Classes</guid> 
    </item> 

</channel> 
</rss>