Jsoup serves as an HTML (XML) parser that allows you to extract JavaScript from a web page's source code. An example of how you can achieve this is by using the following code snippet:
Elements scripts = document.select("script");
After extracting the script, you will need to parse it yourself, which can be done using regular expressions. Below is an illustration:
final String itemName = "productName";
final String regex = "#" + itemName + ".*?value\\((.*?)\\)";
final String scriptContent = "$(document).ready(function(){ \n"
+ " $(\"#productName\").value(1);$(\"#category\").value(12);\n"
+ "}";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(scriptContent);
if (matcher.find() && matcher.groupCount() > 0) {
String productName = matcher.group(1);
System.out.println(itemName + ": " + productName);
}