Java - Obtain text within script tag using Jsoup

后端 未结 4 1980
渐次进展
渐次进展 2021-01-01 12:19

I am using the Jsoup library to read a URL. This url has text within a few

4条回答
  •  春和景丽
    2021-01-01 12:47

    According to your case the solution will be as below.

    Document doc = Jsoup.connect("http://www.example.com").timeout(10000).get();
    Elements scripts = doc.select("script");
    
    for (Element script : scripts) {
        String type = script.attr("type");
        if (type.contentEquals("text/javascript")) {
            String scriptData = script.data(); // your text from the script
            break;
        }
    }
    

提交回复
热议问题