Reputation: 45
In the html page there is a javascript like the below and i want to extract the values of the var number.
<script type="text/javascript">
var number= 4443;
</script>
I am using jsoup to parse an html page using this command.
org.jsoup.nodes.Document doc3 = Jsoup.connect("http://htmlpage.com").get();
How can i do it ? Thank you all in advance.
Upvotes: 2
Views: 2132
Reputation: 1108712
Jsoup is a HTML parser, not a JS parser. Best what you could get with Jsoup is getting the HTML <script>
element(s).
Elements scripts = doc3.select("script");
Its contents has then to be extracted as text by Element#text()
and parsed further by a different library which is capable of parsing JS code, such as Mozilla Rhino. You could of course also perform trivial String
parsing using indexOf()
, substring()
, etc methods or perhaps even using some good regex.
Upvotes: 1