Reputation: 3329
I have an HTML with a javascript as below.
<script type="text/javascript">
if (mnt) {
event.update();
} else {
event.delete();;
}
cf.lmt('45000', '1131452100000', '');</script>
How do I use JSoup to parser this script tag and get the value '1131452100000' which is present in the last line of the script.(which is nothing but an argument). any inputs are appreciated.
Upvotes: 1
Views: 9055
Reputation: 1
doc.select("script[type=text/javascript]:not([src~=[a-zA-Z0-9./\s]+)");
Upvotes: 0
Reputation: 49557
I am afraid you can't parse javascript
using Jsoup
to extract your data. Basically Jsoup is an HTML pasrser and HTML and javascript are totally different things.You can see even there are no HTML tags in javascript which jsoup can understand.
You can do one thing load all your content between <script></script>
tags into a string and than use regex
to fetch the required content.
Here is a nice Regex Java Tutorial.
OR You can try using Rhino from Mozilla and using its integration libraries.
Upvotes: 4
Reputation: 7210
You can't use JSoup. It's an HTML parser not a Javascript parser. Try Rhino. You should have javax.script
available.
Upvotes: 1