Geek
Geek

Reputation: 3329

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?

Upvotes: 4

Views: 9314

Answers (2)

Rodrigo Gauzmanf
Rodrigo Gauzmanf

Reputation: 2527

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 :(");
}

Upvotes: 26

Hauke Ingmar Schmidt
Hauke Ingmar Schmidt

Reputation: 11607

This

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

selects the div with the two classes.

Upvotes: 0

Related Questions