【发布时间】: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
【问题讨论】:
-
请发布您的代码!
我想从 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
【问题讨论】:
您必须使用 CSS 选择器查询:
doc.select("div").first().text();
doc.select("span").first().text();
doc.select("div > span + p ").first().text();
【讨论】: