jsoup类名空格,jcoup1.8.1不能使用document..select(“div [class ='a b c']”)

时间:2017-05-05 05:55:00

标签: jsoup

String html = "<div class='a b c'>helloworld</div>" + 
              "<div class='b a c'>thanks</div>"; 
Document doc = Jsoup.parse(html);
doc.select("div[class='a b c']");

没有效果,我想得到第一个div,我该怎么办?

谢谢!

1 个答案:

答案 0 :(得分:0)

Jsoup忽略了这个空间。您必须尝试这样才能获得第一个div

 String html = "<div class='a b c'> helloworld</div>    <div class='b a c'>thanks</div>";
    Document doc = Jsoup.parse(html);  
    System.out.println(doc.select("div:eq(0)")); 
   //if  you need plain text you can use like below
   System.out.println(doc.select("div:eq(0)").text());