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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.