【问题标题】:Get text between html tags using jsoup使用jsoup获取html标签之间的文本
【发布时间】:2015-04-07 17:35:15
【问题描述】:

我想从 HTML 标记中检索文本并对文本应用索引。

输入

<div>this <span>is</span> my<p>first</p>program</div>  

输出

<div> this 1
<span> is  2
<div> my  3
<p>   first 4
<div> program 5

【问题讨论】:

  • 请发布您的代码!

标签: java html jsoup


【解决方案1】:

您必须使用 CSS 选择器查询:

doc.select("div").first().text();
doc.select("span").first().text();
doc.select("div > span + p ").first().text();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多