Search code examples
javajsoup

Find "Span" that is within "div" in HTML using JSoup


I'm trying to find the text that is within this span here using JSoup: <div class="_6wab"><span>$35 raised</span>

I have successfully gotten text within a divider that looks like this: <div class="_6wae">Time</div>

Using this:

Document doc = Jsoup.connect("https://" + line).userAgent("Mozilla/17.0").get();
String goal = doc.select("div._6wae").html();

So I know my method works for finding a text within a divider, but I'm not sure how to find the text within a span, within a divider.

Thanks so much in advance!


Solution

  • This code might work.

    Primarily, find the first div with class '_6wab'.

    Element div = doc.getElementsByClass("_6wab").first();
    

    Then, after getting the div, find the inner span.

      Element span = div.select("span").first();
    

    Finally, get the text.

    System.out.println(span.text());