jsoup 中的选择器语法

Selector syntax in jsoup

我想获取任何标签的文本,该标签包含一个属性,其中有一个描述值。

例如:-

<div id="id_description"> value to be fetched </div>
<span class="a-list-description-value">value to be fetched </span>

我怎样才能做到这一点?

此方法将从任何具有包含术语 "description" 的属性的元素中获取文本,并将其存储到 ArrayList:

ArrayList<String> results = new ArrayList<String>();

for(Element e : doc.getAllElements()) {
    for(Attribute attribute : e.attributes()) {
        if(attribute.getValue().contains("description")) {
            results.add(e.text());
        }
    }
}

使用您的示例 HTML,results 将包含:

[value to be fetched, value to be fetched]