Search code examples
javaparsingjsoup

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 label. 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?


Solution

  • This

    Elements divs = doc.select("article > a[href] > span[class=mick vtEnabled]");
    

    selects the div with the two classes.