【发布时间】:2015-03-21 16:42:26
【问题描述】:
我正在尝试让网络爬虫在网页上找到给定单词时返回 true。 return true 语句从不运行,所以我不能正确使用它。任何人都有一个简单的方法来做到这一点?谢谢
public static boolean keywordSearch(String url, String keyword){
String strTemp = "";
try {
URL my_url = new URL(url);
BufferedReader br = new BufferedReader(new InputStreamReader(my_url.openStream()));
while(null != (strTemp = br.readLine())){
if (strTemp.contains(keyword)){
return true;
}
}
} catch (Exception ex) {
System.out.println("Error: " + ex.getMessage());
}
return false;
}
【问题讨论】:
-
你的方法对我有用。它返回
true用于在该问题的URL 中搜索单词“keyword”。为什么您认为它不起作用,您能否提供一个示例 URL 和关键字,它应该起作用但不起作用?
标签: java web web-crawler