admin管理员组

文章数量:1403443

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.

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.

Share Improve this question asked Jan 24, 2012 at 20:49 GeekGeek 3,32916 gold badges79 silver badges122 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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.

You can't use JSoup. It's an HTML parser not a Javascript parser. Try Rhino. You should have javax.script available.

doc.select("script[type=text/javascript]:not([src~=[a-zA-Z0-9./\s]+)");

本文标签: javaJSoup to parse ltscriptgt tagStack Overflow