如何以编程方式从博客站点查找博客供稿URL

时间:2012-02-27 04:37:19

标签: java rss blogs google-reader rome

我们使用以下代码来阅读RSS | ATOM feed,有没有办法找到RSS |博客订阅源的ATOM URL提供博客站点(例如for http://my.typepad.com or http://occupylosangeles.org/)。这应该类似于google.com/reader所做的。

import com.sun.syndication.feed.atom.Feed;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.synd.SyndCategory;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.sun.syndication.fetcher.FeedFetcher;
import com.sun.syndication.fetcher.FetcherEvent;
import com.sun.syndication.fetcher.FetcherListener;
import com.sun.syndication.fetcher.impl.FeedFetcherCache;
import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;
import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
    FeedFetcher fetcher = new HttpURLFeedFetcher(feedInfoCache);
    // register listener to feed
    FetcherEventListenerImpl listener = new FetcherEventListenerImpl();
    fetcher.addFetcherEventListener(listener);

    // Mechanism to read feeds via Rome Fetcher
    SyndFeed feed = fetcher.retrieveFeed(new URL(feedURL));

1 个答案:

答案 0 :(得分:1)

罗马似乎没有这样的功能,但有一种方法。在HTML源代码中查找特定元素:

<link rel="alternate" type="application/rss+xml" href="http://url-of-an-rss-feed">

reltype值应与此完全相同,href将包含Feed的网址。

还有一种方法可以通过发送这样的请求来使用AJAX Feed API

http://ajax.googleapis.com/ajax/services/feed/lookup?v=1.0&q=YOUR-PAGE-URL

source