【发布时间】:2014-05-11 03:43:17
【问题描述】:
我正在使用 jsoup 遍历一个元素列表,但需要定期找到一个不直接出现在当前元素之后的元素。
例如,如果我正在迭代并找到一个 img 标记,我想找到在该 img 标记之后出现的下一个 a 标记。但是,两者之间可能有一些标签。
下面是一些示例代码:
for (Element e : elements) {
if (e.tagName().equalsIgnoreCase("img")) {
// Do some stuff with "img" tag
// Now, find the next tag in the list with tag <a>
}
// Do some other things before the next loop iteration
}
我认为像 e.select("img ~ a") 这样的东西应该可以工作,但它没有返回任何结果。
在 jsoup 中有什么好的方法?
【问题讨论】: