Neil Neil - 6 months ago 17
Java Question

How to parse using jsoup

Giving

<div class="alert_right">
<p>welcome!<script>setTimeout("window.location.href ='index.php';", 1000);</script></p></div>


How to get the welcome! text using Jsoup?

TDG TDG
Answer

If your HTML is in a String, you can use the following code:

Document doc = Jsoup.parse(HTML);
Elements div =  doc.select(".alert_right > p:nth-child(1)");
String s = div.text();

Now s is welcome!