简体   繁体   English

如何使用 Jsoup 计算网页的评论和行数?

[英]How can I count the Comments and the lines of a webpage using Jsoup?

大家好,我正在尝试使用 jsoup 制作 html 解析器。如何计算 html 文档的注释和行数?

As already answered you can iterate over every Node , check if it's an Instance of Comment and count.正如已经回答的那样,您可以遍历每个Node ,检查它是否是Comment和 count 的实例。

Counting the lines of the HTML can be done by splitting it at every line-break:可以通过在每个换行符处将其拆分来计算 HTML 的行数:

int lines = doc.html().split(System.getProperty("line.separator")).length;

Use selector syntax api for tags which are related to comments.对与评论相关的标签使用选择器语法 api。 (It's not the same tag for any websites.) Also, you may find the tags which you need to parse via browser's dev tools. (它不是任何网站的相同标签。)此外,您可能会通过浏览器的开发工具找到需要解析的标签。 (firebug, chrome dev tool etc.) (萤火虫、chrome 开发工具等)

Selector syntax for jsoup jsoup 的选择器语法

Good luck...祝你好运...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM