<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个值。 它们总是在“强”标签之后,并由br标签分隔。怎么做?
提前致谢
答案 0 :(得分:1)
您可以这样做:
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
(还有两行单一'')