Java 如何使用Jsoup在网站上搜索字符串?
我正在尝试使用Jsoup搜索网站,查看它是否包含字符串。这可能吗?如果可能的话,是如何做到的?是的,如果您使用Jsoup,这是可能的,而且实际上相当简单。要查看特定网页是否包含特定字符串,可以执行以下操作: 假设我们想查看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
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...
}