Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用Jsoup在网站上搜索字符串?_Java_Html_Parsing_Jsoup - Fatal编程技术网

Java 如何使用Jsoup在网站上搜索字符串?

Java 如何使用Jsoup在网站上搜索字符串?,java,html,parsing,jsoup,Java,Html,Parsing,Jsoup,我正在尝试使用Jsoup搜索网站,查看它是否包含字符串。这可能吗?如果可能的话,是如何做到的?是的,如果您使用Jsoup,这是可能的,而且实际上相当简单。要查看特定网页是否包含特定字符串,可以执行以下操作: 假设我们想查看Jsoup主页()中是否存在以下字符串: 您的代码可能如下所示: String stringToFind = "If you have any questions on how to use jsoup"; try { Document doc = Jsoup.conn

我正在尝试使用Jsoup搜索网站,查看它是否包含字符串。这可能吗?如果可能的话,是如何做到的?

是的,如果您使用Jsoup,这是可能的,而且实际上相当简单。要查看特定网页是否包含特定字符串,可以执行以下操作:

假设我们想查看Jsoup主页()中是否存在以下字符串:

您的代码可能如下所示:

String stringToFind = "If you have any questions on how to use jsoup";
try {
    Document doc = Jsoup.connect("https://jsoup.org/").get();
    if (doc.text().contains(stringToFind)) {
        System.out.println("Yes...String exists in web-page.");
    }
    else {
        System.out.println("No...String does not exist in web-page.");
    }
}
catch (IOException ex) {
    // Do whatever you like to handle the exception...
}

你试过什么?你看过这里的文件了吗?
String stringToFind = "If you have any questions on how to use jsoup";
try {
    Document doc = Jsoup.connect("https://jsoup.org/").get();
    if (doc.text().contains(stringToFind)) {
        System.out.println("Yes...String exists in web-page.");
    }
    else {
        System.out.println("No...String does not exist in web-page.");
    }
}
catch (IOException ex) {
    // Do whatever you like to handle the exception...
}