问题描述:

I have parts of html for parsing:

<a href="/res/" class="postbtn-reply-href" name="112309691"></a>

<blockquote id="m112309691" class="post-message"> text </blockquote>

How can I do it with different attributes?

  • for <a> attribut is ["name"]
  • for <blockquote> it is text()

something like:

Elements elements = doc.select("a [class=postbtn-reply-href]["name"], blockquote[class=post-message] [text()]");

网友答案:

What about this CSS selector?

a.postbtn-reply-href[name], blockquote.post-message:contains(text)

DEMO: http://try.jsoup.org/~kPbUK0RX6brMZFZZH-U-u9yVukY


The initial CSS selector is understood like below by 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()

References:

  • Jsoup Selector syntax
  • Jsoup 1.8.3
网友答案:

try this (element.class-name)

   doc.select("a.postbtn-reply-href[name=112309691]")+""+doc.select("blockquote.post-message").text();
相关阅读:
Top