2010-04-12 4 views
0

은 무엇 메신저 일을하려고 :PHP 스크립트로 새로운 RSS 항목 만 가져 오기?

는 RSS 내 블로그에서 피드의 X 번호를 가져옵니다 만 새로운 항목을 에코. 내 문제는, 이미 항목이 파싱 된 것을 아는 법입니까? 지금까지

솔루션 :

는, 피드마다 5 시간 페치 데이터베이스 테이블 또는 플랫 파일 내에서 모든 제목을 저장합니다. 다음으로 제목이 이미 데이터베이스에 있는지 확인하고 인쇄하지 않으면 데이터베이스에 저장하십시오.

그러나 이것이 최선의 방법인지 확실하지 않습니다.

누군가가 빠른 길을 알고 있다면 좋을 것입니다. 내 가난한 영어 미안해.

답변

3

구문 분석중인 블로그 항목에 날짜 표시기가있는 경우 DATETIME 형식의 CREATE 필드가 있습니다. 이 날짜 값을 저장하십시오. 그런 다음 구문 분석 할 때 최신 DATETIME SELECT MAX(CREATED) FROM posts LIMIT 1을 선택하고 이전 날짜가있는 항목을 삽입하지 마십시오.

일부 블로그가 RSS를 지연으로 업데이트하지만 이전 날짜를 타임 스탬프로 유지하려는 경우이 솔루션은 약간의 단점이있을 수 있습니다.

1

내가 가져온 마지막 소식의 날짜를 저장해야한다고 생각합니다. 다음 번에 가져올 때 저장 한 날짜보다 오래된 것만 수집 할 수 있습니다.

+0

ID는 다른 형식이 다른 저장 메커니즘을 가지고 있기 때문에 매우 위험합니다. 모두 정확하게 읽는 것에 달려 있습니다. –

0

모든 피드에는 고유 한 ID가 있습니다. ID를 확인하고 제목을 저장하는 대신 데이터베이스에 저장할 수 있습니다.

내가 평소 연습이 RSS 피드에 GUID 요소 떨어져 일이라고 생각 Pubsubhb http://superfeedr.com/documentation#pubsubhubbub

1

에서 문서를 읽어보십시오. 이것은 때로는 소스 아티클의 URI이며 때로는 숫자이며 때로는 전통적인 GUID입니다.

기사를 이미 받았는지 확인하기 위해이 요소를 사용하면 날짜를 구문 분석 할 필요가 없으며 Google 리더는 일반적으로 항목이 이미 수집되었는지 여부를 결정합니다.

<?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> 
관련 문제