//get source code
String html = new Scanner(new URL("http://example.com/").openStream(), StandardCharsets.UTF_8).useDelimiter("\\A").next();
//parse as jsoup html
Document doc = Jsoup.parse(html);
//find all script elements
Elements scriptElements = doc.getElementsByTag("script");
//all code after here is debug purposes and this is where i need help
for (Element element :scriptElements ){
for (DataNode node : element.dataNodes()) {
System.out.println(node.getWholeData());
System.out.println(element);
}
System.out.println("-------------------");
}
Итак, я пытаюсь получить текст из элемента скрипта и проанализировать его как JSONObject.Код прилагается.
Проблема в том, что существует несколько элементов сценария, и я не знаю, как получить текст одного из них.Спасибо за любую помощь
Я проверил другие потоки переполнения стека и другие веб-сайты для любого ответа, но я не могу понять это.