package com.ttol.spider;
import java.io.IOException;
import java.net.URL;
import
java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import
org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class SpiderRss {
public static void main(String[] args) {
String
file="c:\\onlinedown.xml";
String url="http://www.chong4.com.cn";
SAXBuilder
builder = new SAXBuilder();
try {
Document
doc = builder.build(new
URL(url));
Element
root=doc.getRootElement();
Element el=root.getChild("channel"); //rss2.0
List
listitem=el.getChildren("item");//rss2.0
System.out.println("共有="+listitem.size());
for(int
i=0;i<listitem.size();i++)
{
Element e =
(Element)listitem.get(i);
System.out.println("title="+e.getChildText("title"));
System.out.println("link="+e.getChildText("link"));
System.out.println("category="+e.getChildText("category"));
System.out.println("description="+e.getChildText("description"));
System.out.println();
System.out.println();
}
}
catch
(JDOMException e) {
// TODO Auto-generated catch
block
e.printStackTrace();
} catch
(IOException e) {
// TODO Auto-generated catch
block
e.printStackTrace();
}
}
}本文出自 “9824709” 博客,请务必保留此出处http://dansy.blog.51cto.com/9824709/1601576
原文:http://dansy.blog.51cto.com/9824709/1601576