skip to Main Content

i’m trying to get the text in the reference class div without getting the text in the inner div.

I just want what’s inside a <div class="class1"> -> "123456789" without taking "abcdefg".

<div class="class0"> 
 <div class="class1"> 
  <div class="class2">
      abcdefg      
  </div> 
   123456789
 </div> 
</div>

i tried to run this but it always takes the text i don’t want

String text = doc.getElementsByClass("class1").html();
String text2 = text.replaceAll("</?div[^>]*>","");
Log.d("text2", text2 );

output:
abcdefg      
123456789

but I just want 123456789
how can I do? thank you all

2

Answers


  1. Chosen as BEST ANSWER

    i solved now by myself

    doc.select("div.class2").first().remove();
    String text = doc.getElementsByClass("class1").html();
    

  2. Try

    text = document.getElementsByClassName("class1");
    text[0].outerText.split('n')[1];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search