<div class="unique_class">
<h2>
...
</h2>
<h2>
...
</h2>
<strong>
unique strong before content
</strong>
</br>
static title 1: value 1
</br>
static title 2: value 2
</br>
static title 3: value 3
</br>
static title 4: value 4
</br>
</br>
</div>
我需要使用 JSOUP 获取这 4 个值。 它们始终位于“strong”标签之后,并由 br 标签分隔。怎么做?
提前致谢
最佳答案
你可以这样做:
Document doc = // ... eg. parse File / String here or connect to a website
Node value;
for( Element element : doc.select("strong ~ *") )
{
// element.previousSibling() is possible too
value = element.nextSibling();
System.out.println(value);
}
这将打印:
static title 1: value 1
static title 2: value 2
static title 3: value 3
static title 4: value 4
(还有两行带有一个“”)
关于java - 获取元素后用 br 分隔的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12886644/