集册 Java实例教程 读取RSS提要并输出到控制台

读取RSS提要并输出到控制台

欢马劈雪     最近更新时间:2020-01-02 10:19:05

585
阅读RSS提要并输出到控制台

/** *************************************************

 * Basic code to read a RSS feed and output to console

 * to testing if working.

 *

 * Dependencies: jdom-1.1.1.jar

 *               rome-1.0.jar

 *

 * ************************************************** */
 /* 
 *来 自
  NowJava.com - 时代Java
 */




import java.net.HttpURLConnection;

import java.net.URL;

import java.util.Iterator;

import java.util.List;


import com.sun.syndication.feed.synd.SyndEntry;

import com.sun.syndication.feed.synd.SyndFeed;

import com.sun.syndication.io.SyndFeedInput;

import com.sun.syndication.io.XmlReader;


public class RomeEx3 {

    public static void main(String[] args) throws Exception {// 来 自 时 代      J a v a   公   众 号 - nowjava.com

        URL url = new URL("http://feeds.reuters.com/reuters/topNews");

        HttpURLConnection httpcon = (HttpURLConnection) url

                .openConnection();

        // Reading the feed

        SyndFeedInput input = new SyndFeedInput();

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

        List<SyndEntry> entries = feed.getEntries();

        Iterator<SyndEntry> itEntries = entries.iterator();


        while (itEntries.hasNext()) {

            SyndEntry entry = itEntries.next();

            System.out.println("Title: " + entry.getTitle());

            System.out.println("Link: " + entry.getLink());

            System.ou
展开阅读全文