我想抓取雅虎,并获得前10名匹配关键字的结果。搜索雅虎答案使用Jsoup
我使用this链接抓取的结果我使用这个
代码是:
public static void main(String args[]) throws IOException
{
try
{
Document doc = Jsoup.connect("https://in.search.yahoo.com/search;_ylt=AibrWnqoneznrEAiS9bG0aOuitIF?p=solar+systems&toggle=1&cop=mss&ei=UTF-8&fr=yfp-t-405").get();
for(Element dc : doc.select("div#doc.uh3-p uh3lite"))
{
System.out.println("data");
for(Element dd : doc.select("div#bd"))
{
for(Element results : doc.select("div#results"))
{
for(Element wb : doc.select("div#web"))
{
Elements data=wb.select("span");
if(data.size()>0)
{
System.out.println(data.get(0).text());
}
}
}
}
}
}
catch(Exception ex)
{
System.out.println(ex);
}
}
我得到它没有结果。谁能帮我?
您是否阅读过该网站的robots.txt文件?我很确定它不允许网络爬行。 –
@JechtTyre雅虎允许我们抓取其搜索到的链接..我能够抓取数据.. –
只是因为你能够不意味着它被允许。检查这个链接:[http://search.yahoo.com/robots.txt](http://search.yahoo.com/robots.txt)。你应该能够看到通用的“禁止:/搜索” –