【发布时间】:2016-01-27 15:30:16
【问题描述】:
我正在使用 JSoup 来抓取网络并获取结果。我想执行关键字搜索。例如我爬 http://www.business-standard.com/ 用于以下关键字:
谷歌海得拉巴
它应该为我提供链接:
我写了下面的代码,但没有给我合适的结果。
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 App {
public static void main(String[] args) {
Document doc;
try {
doc = Jsoup.connect("http://www.business-standard.com").userAgent("Mozilla").get();
String title = doc.title();
System.out.println("title : " + title);
Elements links = doc.select("a:contains(google)");
for (Element link : links) {
System.out.println("\nlink : " + link.attr("href"));
System.out.println("text : " + link.text());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
结果如下:
标题:印度新闻、最新新闻头条、疯牛病直播、NSE 直播、股市直播、财经新闻、商业新闻和印度经济市场分析 - 商业标准新闻 链接:/photo-gallery/current-affairs/mumbai-central-turns-into-wi-fi-zone-courtesy-google-power-2574.htm 文字:孟买中心变成 Wi-Fi 区,由 Google 提供 链接:plus.google.com/+businessstandard/posts 文字:谷歌+Jsoup 1.8.2
【问题讨论】:
-
你的问题是什么?
-
Google 抓取网络并将其抓取的内容作为两个单独的进程编制索引。
-
没有得到适当的结果是什么意思?任何不允许的 4 字母单词?
-
结果如下:- 标题:印度新闻、最新新闻头条、BSE 直播、NSE 直播、股市直播、财经新闻、商业新闻和印度经济市场分析 - 商业标准新闻链接:/photo-gallery/current-affairs/mumbai-central-turns-into-wi-fi-zone-courtesy-google-power-2574.htm 文本:孟买中心变成 Wi-Fi 区,由 Google 电源提供链接:plus.google.com/+businessstandard/posts 文字:Google+
-
您需要定义一个规则来确定“关键字”是什么。然后您需要索引这些用法,并且您的搜索需要以该数据集为基础。 JSoup 只会成为更大解决方案的一小部分(充其量)。
标签: java web-crawler jsoup