我有部分html用于解析:
<a href="/res/" class="postbtn-reply-href" name="112309691"></a>
<blockquote id="m112309691" class="post-message"> text </blockquote>
如何使用不同的属性进行操作?
<a>
attribut是[&#34; name&#34;]
<blockquote>
,它是text()类似的东西:
Elements elements = doc.select("a [class=postbtn-reply-href]["name"], blockquote[class=post-message] [text()]");
答案 0 :(得分:1)
这个CSS选择器怎么样?
a.postbtn-reply-href[name], blockquote.post-message:contains(text)
DEMO:http://try.jsoup.org/~kPbUK0RX6brMZFZZH-U-u9yVukY
初始的CSS选择器如下所述:Jsoup:
a // Select node descendant of a anchor node (a),
[class=postbtn-reply-href] // having a class named postbtn-reply-href
["name"] // and an attribute called "name"
, // OR
blockquote[class=post-message] // Select a node descendant of any blockquote having a class named post-message
[text()] // and having an attribute called text()
<强>参考文献:强>
答案 1 :(得分:0)
试试这个(element.class-name)
doc.select("a.postbtn-reply-href[name=112309691]")+""+doc.select("blockquote.post-message").text();