Search code examples
javajsoupgoogle-search

How to do a Google Search with Jsoup


i have to use this Code to search in google and Show the result Link,but i dont know how to send My Query

    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" is my query that i want to search it in google How can i use this method to search my problem is sending query to Google search page


Solution

  • Change Jsoup.connect("http://google.com/search?q=") to Jsoup.connect("http://google.com/search?q=" + s).

    And remove the .data(???).