0

I already searched for it but didn't find an answer. How can I get this Text with Jsoup?

<html>
<body>

<div class="content">Don't want to get this Text</div

<div class="content">WANT TO GET THIS TEXT</div

<div class="content">WANT TO GET THIS TEXT</div>

<div class="content">Don't want to get this Text</div

</body>
</html>

What goes into the question marks?

Elements text = document.select("???");
thankyou
  • 211
  • 1
  • 5
  • 13
  • what have you tried ? what did you not find in the tutorial http://jsoup.org/cookbook/extracting-data/selector-syntax ? – njzk2 Feb 04 '14 at 14:10
  • @njzk2 I already did this tutorial a few days ago. But I think you didn't get what I want to do. I want to get the two divs whith class="content" but not all divs with class="content" ;) And no it's not a duplicate. Mine is a little bit more tricky ;) – thankyou Feb 04 '14 at 14:14
  • if I understand correctly, you want #content, but not first or last ? see this question http://stackoverflow.com/questions/7788018/css-selector-for-other-than-the-first-child-and-last-child – njzk2 Feb 04 '14 at 14:36

1 Answers1

0

Select all div.content and get the first and second

    Elements els = doc.select("div.content");
    System.out.println(els.get(1).text());
    System.out.println(els.get(2).text());

or

    Elements els = doc.select("div.content:eq(1)");
    System.out.println(els.first().text());
    els = doc.select("div.content:eq(2)");
    System.out.println(els.first().text());
Liviu Stirb
  • 5,876
  • 3
  • 35
  • 40