从网站中提取JavaScript行';使用JSoup创建源代码

从网站中提取JavaScript行';使用JSoup创建源代码,java,jsoup,Java,Jsoup,我有一个网站上的JavaScript源代码 <script>"@context": "http://schema.org/","@type": "Product","name": "Shower head","image": "https://example.com/jpeg.png","description": "Hello stackoverflow","url": "link.com","offers": {"@type": "Offer","priceCurrency":

我有一个网站上的JavaScript源代码

<script>"@context": "http://schema.org/","@type": "Product","name": "Shower head","image": "https://example.com/jpeg.png","description": "Hello stackoverflow","url": "link.com","offers": {"@type": "Offer","priceCurrency": "USD","price": "10.00","itemCondition": "http://schema.org/NewCondition","availability": "http://schema.org/InStock","url": "MyUrl.com","availableAtOrFrom": {"@type": "Place","name": "Geneva, NY","geo": {"@type": "GeoCoordinates","latitude": "42.8361","longitude": "-76.9874"}},"seller": {"@type": "Person","name": "Edward"}}}</script>

有人能帮我吗,还是不可能

JSoup正在解释HTML。
元素的内容包含JavaScript,因此JSoup无法解释
元素中的内容

看起来
元素的内容是用JSON格式化的。因此,您可以使用JSoup访问
元素的内容,然后尝试将该字符串放入JSON解释库中。如果你想深入了解这一点,请看这里:

如果这是一次性的,并且您可以相信
元素的内容不会改变太多,那么您也可以使用正则表达式来获得所需的部分。但是,我建议使用JSON库

public class JsoupCrawler {
    public static void main(String[] args) {
        try {
            Document doc = Jsoup.connect("https://example.com").userAgent("mozilla/17.0").get();
            Elements temp = doc.select("script.name");
            int i=0;
            for (Element nameList:temp) {
              i++;
              System.out.println(i+  " "+ nameList.getElementsByTag(" ").first().text() );
            } 
        }  
        catch (IOException e) {
            ex.printStackTrace();  
        } 
    }
}