如何使用Jsoup进行Google搜索

时间:2014-01-11 12:18:14

标签: java jsoup google-search

我必须使用此代码在谷歌搜索并显示结果链接,但我不知道如何发送我的查询

    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"));
    }

}

“reza”是我的查询,我想在谷歌搜索它 我该如何使用此方法进行搜索 我的问题是向Google搜索页面发送查询

1 个答案:

答案 0 :(得分:1)

Jsoup.connect("http://google.com/search?q=")更改为Jsoup.connect("http://google.com/search?q=" + s)

然后移除.data(???)