2014-01-11 106 views
0

我必須使用這個代碼在谷歌搜索和顯示結果的鏈接,但我不知道如何發送我的查詢如何做一個谷歌搜索與Jsoup

String s="reza"; 
    Document doc = Jsoup.connect("http://google.com/search?q=").userAgent("Mozilla").data(?????).get(); 
    Elements titles = doc.select(".entrytitle"); 

    //print all titles in main page 
    for(Element e: titles){ 
     System.out.println("text: " +e.text()); 
     System.out.println("html: "+ e.html()); 
    } 

    //print all available links on page 
    Elements links = doc.select("a[href]"); 
    for(Element l: links){ 
     System.out.println("link: " +l.attr("abs:href")); 
    } 

} 

「禮」是我的查詢我想尋找它在谷歌 我怎麼可以用這種方法來搜索 我的問題是在發送查詢到谷歌搜索頁面

+0

谷歌不允許自動請求,所以問題是關於如何濫用谷歌的服務。 – newbie

+0

但是如果你只做了幾次,對於一些非常有限的短期目的,它應該沒問題。 –

回答

1

變化Jsoup.connect("http://google.com/search?q=")Jsoup.connect("http://google.com/search?q=" + s)

並刪除.data(???)