I need to get a random word from a webpage and I'm using Jsoup to do this.
Here is the HTML code:
<script language="javascript">
function RandomWord() {
var requestStr = "http://randomword.setgetgo.com/get.php";
$.ajax({
type: "GET",
url: requestStr,
dataType: "jsonp",
jsonpCallback: 'RandomWordComplete'
});
}
function RandomWordComplete(data) {
$("#body").html(data.Word);
}
</script>
<body id="body" onload="RandomWord();">
</body>
and here is the java code:
public static void getRandomWord() throws MalformedURLException, IOException {
Document doc = Jsoup.connect("http://mywebsite.net/rand.html").get();
Elements body = doc.select("#body");
System.out.println(doc.text());
}
When I run this the output is empty.. Not sure what the problem is.