Home > Software design >  Android remove a class inside div
Android remove a class inside div

Time:05-20

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 > -> "123456789" without taking "abcdefg".

<div > 
 <div > 
  <div >
      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

CodePudding user response:

try text = document.getElementsByClassName("class1"); text[0].outerText.split('\n')[1];

CodePudding user response:

i solved now by myself

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