作者mahoihei (Alvar)
看板java
标题Re: [问题] HTML PARSER出包了,还是我使用方法错了?
时间Sun Jun 12 19:56:08 2011
用了HTMLCLEANER,可是出来的结果都是一样
code:
public static void main(String args[]) throws IOException {
URL url = new URL("
http://www.discuss.com.hk/archiver/");
HtmlCleaner cleaner = new HtmlCleaner();
TagNode nodes = cleaner.clean(url);
TagNode[] nodeArray = nodes.getElementsByName("ul", true)[0].getAllElements(false);
Map nodeMap = nodes.getElementsByName("ul", true)[0].getAttributes();
System.out.println(nodeMap);
for(int i = 0; i < nodeArray.length; i++) {
System.out.println(nodeArray[i].getText());
}
output:
{class=archiver_forumlist}
论坛资讯
最新消息
香港讨论区 Android App (测试版) 意见收集
香港讨论区 iPhone App ( ver. 1.2) 意见收集
会员教学及意见
(略N行N字)
吹水闲聊
吹水广场
抓出来的确实是<ul class="archiver_forumlist">这个TAG的内容,可以少了很多..
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 116.49.240.161
1F:推 swpoker:有的时候是HTML本身就有问题了~~ 06/15 14:26