rome的一个小例子,读取rss数据

| No Comments | No TrackBacks

用了rome 0,8的jar包,代码大部分来自于rome-samples-0.7 。其中加入了一个设置代理的代码,因为本机的环境需要设置代理才行,呵呵,等以后加强功能的时候这个设置还是挺有用的东西

对了,放个rome的链接Rome's Home,可以直接去下载

import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

import java.net.*;
import java.util.Properties;


/**
 * @author dozhan
 *
 */


public class Writer {
 
    public static void main(String[] args){
        System.out.println("Start...");
        String str ="http://blog.csdn.net/zdsdiablo/Rss.aspx";
        Properties prop = System.getProperties();
        prop.put("http.proxyHost","192.168.0.1");    //这里填写代理的ip
        prop.put("http.proxyPort","8080");

        boolean ok = false;
        try {         

            URL feedUrl = new URL(str);

            SyndFeedInput input = new SyndFeedInput();

            SyndFeed feed = input.build(new XmlReader(feedUrl));

            System.out.println(feed);

            ok = true;
        }
        catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("ERROR: "+ex.getMessage());
        }


        if (!ok) {
            System.out.println();
            System.out.println("FeedReader reads and prints any RSS/Atom feed type.");
            System.out.println("The first parameter must be the URL of the feed to read.");
            System.out.println();
        }
       
    }
}

 

Start...
SyndFeedImpl.contributors=null
SyndFeedImpl.title=十分钟年华老去
SyndFeedImpl.categories=[]
SyndFeedImpl.link=http://blog.csdn.net/zdsdiablo/
SyndFeedImpl.publishedDate=null
SyndFeedImpl.entries[0].updatedDate=null
SyndFeedImpl.entries[0].contributors=null
SyndFeedImpl.entries[0].title=Java API文档中文版
SyndFeedImpl.entries[0].categories=[]
SyndFeedImpl.entries[0].link=http://blog.csdn.net/zdsdiablo/archive/2006/06/09/782902.aspx
SyndFeedImpl.entries[0].publishedDate=Fri Jun 09 22:35:00 GMT+08:00 2006
SyndFeedImpl.entries[0].authors=null

No TrackBacks

TrackBack URL: http://www.wujianrong.com/mt-tb.cgi/1433

Leave a comment

About this Entry

This page contains a single entry by kevinwu published on November 29, 2006 12:10 PM.

用JSP实现基于Web的RSS阅读器 was the previous entry in this blog.

目录遍历的类 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.