删除链接jsoup中的脚本

Lon*_*han 4 java jsoup

我想在读取url而不是文件时删除脚本,请帮帮我

  Document connect =  Jsoup.connect("http://www.tutorialspoint.com/ant/ant_deploying_applications.htm");
            Elements selects = connect.select("div.middle-col");
            System.out.println(selects.removeAttr("script").html());
Run Code Online (Sandbox Code Playgroud)

Sus*_*ngh 5

这是您需要删除脚本元素的方法:

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class TestJsoup {
    public static void main(String args[]) throws IOException {
        Document doc = Jsoup.connect("http://www.tutorialspoint.com/ant/ant_deploying_applications.htm").get();

        Elements selects = doc.select("div.middle-col");
        for (Element script : selects) {
            Elements scripts = script.select("script");
            scripts.remove();
        }   
        System.out.println(selects.html());
    }
}
Run Code Online (Sandbox Code Playgroud)