集册 Java实例教程 使用Rome库获取RSS源

使用Rome库获取RSS源

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

471
使用罗马库获取RSS提要

/** NowJava.com - 时  代  Java 提 供 **/

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

import com.sun.syndication.io.SyndFeedInput;

import com.sun.syndication.io.XmlReader;

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


import java.net.URL;

import java.io.InputStreamReader;

import java.util.List;


public class RomeEx1 {


    public static void main(String[] args) {


        try {

            String urlString = "http://rss.cnn.com/rss/cnn_topstories.rss";

            URL feedUrl = new URL(urlString);

            /*
            N o w  J a v a  . c o m
            */

            SyndFeedInput input = new SyndFeedInput();

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

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


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


            for (SyndEntry entry : entries) {

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

                System.out.println("Unique ID: " 
展开阅读全文