Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jSoup to check if a span class exists

I have a HTML with the following format

<article class="cik" id="100">
<a class="ci" href="/abc/1001/STUFF">
              <img alt="Micky Mouse" src="/images/1001.jpg" />
              <span class="mick vtEnabled"></span>

</a>

<div>
         <a href="/abc/1001/STUFF">Micky Mouse</a>
         <span class="FP">$88.00</span>&nbsp;&nbsp;<span class="SP">$49.90</span>

</div>
</article>

In the above code the tag inside article has a span class="mick vtEnabled" with no lable. I want to check if this span tag with the class name specified is present within the article tag. How do i do that? I tried select("> a[href] > span.mick vtEnabled") and checked the size..it remains 0 for all the article tags irrespective if its set or not. any inputs?

like image 778
Geek Avatar asked Nov 27 '22 22:11

Geek


1 Answers

Element span = doc.select("article.cik > a.ci > span.mick.vtEnabled").first();
if(span != null){
    System.out.println("Exist!!");
}
else {
    System.out.println("No Span :(");
}
like image 190
Rodri_gore Avatar answered Dec 15 '22 04:12

Rodri_gore