我想抓取雅虎,並獲得前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)。你應該能夠看到通用的「禁止:/搜索」 –