htmlparser类的相关知识——原载于我的百度空间

来源:互联网 发布:中经云数据存储 编辑:程序博客网 时间:2024/05/15 20:54

1、org.htmlparser.Node类的toHtml()方法和getText()方法、toPlainTextString()方法的区别

     toHtml()方法的结果 :

<a title="阳光志愿者俱乐部" href="uploads/200911/1257821385echBDgLr.jpg" target="_blank"><img title="阳光志愿者俱乐部" alt="阳光志愿者俱乐部" src="uploads/200911/1257821385echBDgLr_s.jpg"></a><a href="http://www.ygclub.org/wiki/index.php?doc-view-517.html">http://www.ygclub.org/wiki/index.php?doc-view-517.html</a><a href="http://www.ygclub.org/wiki/index.php?doc-view-741.html">http://www.ygclub.org/wiki/index.php?doc-view-741.html</a><a href="http://www.ygclub.org/bbs/thread-2046-1-1.html">http://www.ygclub.org/bbs/thread-2046-1-1.html</a><a href="http://www.ygclub.org/wiki/index.php?doc-view-50">http://www.ygclub.org/wiki/index.php?doc-view-50</a>

    getText()方法的结果:

a title="阳光志愿者俱乐部" href="uploads/200911/1257821385echBDgLr.jpg" target="_blank"a href="http://www.ygclub.org/wiki/index.php?doc-view-517.html"a href="http://www.ygclub.org/wiki/index.php?doc-view-741.html"a href="http://www.ygclub.org/bbs/thread-2046-1-1.html"a href="http://www.ygclub.org/wiki/index.php?doc-view-50"

     toPlainTextString()方法:

http://www.ygclub.org/wiki/index.php?doc-view-517.htmlhttp://www.ygclub.org/wiki/index.php?doc-view-741.htmlhttp://www.ygclub.org/bbs/thread-2046-1-1.htmlhttp://www.ygclub.org/wiki/index.php?doc-view-50

解析的html文本都是:

<a title="阳光志愿者俱乐部" href="uploads/200911/1257821385echBDgLr.jpg" target="_blank"><img title="阳光志愿者俱乐部" alt="阳光志愿者俱乐部" src="uploads/200911/1257821385echBDgLr_s.jpg"></a><a href="http://www.ygclub.org/wiki/index.php?doc-view-517.html">http://www.ygclub.org/wiki/index.php?doc-view-517.html</a><a href="http://www.ygclub.org/wiki/index.php?doc-view-741.html">http://www.ygclub.org/wiki/index.php?doc-view-741.html</a><a href="http://www.ygclub.org/bbs/thread-2046-1-1.html">http://www.ygclub.org/bbs/thread-2046-1-1.html</a><a href="http://www.ygclub.org/wiki/index.php?doc-view-50">http://www.ygclub.org/wiki/index.php?doc-view-50</a>

相比较发现getText只是把Tag里面的内容读出了。toPlainTextString()方法是将<a></a>标签中间夹着的用户可是部分读出来了,因为第一个a标签中夹的是img标签,所以不是用户可视的,便不读出来了。



原创粉丝点击