java - JSOUP HTML 解析器

标签 java html html-parsing jsoup

有没有办法获取元素/标签的起始行号和列号结束行号和列号

我正在创建 HTML 编辑器,需要根据给定的开始和结束行及列号根据某些场景突出显示标签以优化速度。

最佳答案

不,不幸的是,目前 jsoup 无法做到这一点。

At the moment Jsoup does not track line numbers / character positions when parsing, so it's not possible to extract them. As this is not a core use case, I don't want to extend the memory requirements of the DOM by retaining this data. I have thought about possibly adding an optional side-channel way to track it during the parse, in a similar way as how parse errors can be tracked, but haven't focused on implementing that yet.

来源:https://groups.google.com/forum/#!topic/jsoup/lnbYSIZApWw

相反,您可以尝试 Jericho HTML Parser 。在其功能列表中写道:

The row and column number of each position in the source document are easily accessible.

请参阅 javadocs here并研究诸如 getRow()getColumn()getRowColumnVector() 等方法。

关于java - JSOUP HTML 解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20215002/

相关文章:

java - 无法使用 Selenium 打开 Google Chrome Portable

java - 是否可以断言元素的组合

javascript - 将 CSS 类应用于所有行但不应用于表标题

python - 如何使用 python 从 beautifulsoup 输出中删除所有对齐和缩进?

java - Boolean.hashCode()

html - 具有最大宽度和最大高度并保留比例的 Div(仅限 CSS)

html - 如何自动换行标题?

java - 使用 JSoup 解析 HTML

PHP解析无效的html

java - 如何使用 Java 在 WebDriver 中调用外部 JavaScript