RSS 测试

来源:互联网 发布:这么把淘宝店弄上天猫 编辑:程序博客网 时间:2024/05/16 01:19

//main方法

Document document = null;
   
   HttpClient httpClient = new HttpClient();

   GetMethod getMethod = new GetMethod("http://rss.3g.qq.com/rss/info/rss.jsp?channel=news&g_from=bjuni&wap20=true");
   
   httpClient.executeMethod(getMethod);
   
   getMethod.getParams().setParameter(
     HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
   
   String data = getMethod.getResponseBodyAsString();
   
   System.out.println(data);
   
   document = DocumentHelper.parseText(data);
   
   RSSFeedReader r = new RSSFeedReader();
   System.out.print(r.getPubDate(document));

 

//rssfeedreader

 

private String getPubDate(Document document) throws Exception {

  if (document == null) {

   return null;
  }

  // 取更新时间
  Element element = (Element) document
    .selectSingleNode("//channel/pubDate");

  if (element == null) {
   return null;
  }

  String txt_element = element.getTextTrim();

  String pubDate = DateUtil.str2strUsedByRss(txt_element);

  return pubDate;
 }