Search code examples
javajsoup

How to get text from div that has no id and class in jSoup Java


I want to get text from div tag that has no id and class.

<div class="prod-fulfillment-messaging-text">
    <div> This is not found. </div>
</div>

I want to fetch "This is not found" text. Can any body help me that how I can fetch it. Thanks!


Solution

  •  String str = doc.getElementsByClass("prod-fulfillment-messaging-text")
      .first().child(0).text();
    

    Another option could be:

    doc.select("div.prod-fulfillment-messaging-text > div:first-child").text();