title: Google Search with JSoup
body: <p>i trie to search in google with JSoup. The problem that i have is, that the variable query shows not the URL i want when i start searching. 
  Also, how does Jsoup search ? Looking for Title or URL or what ?</p>
  
  <p>public class Start {</p>
  
  <pre><code>public static void main(String[] args) {
      try {
          new Google().Searching("Möbel Beck GmbH &amp; Co.KG");
      } catch (Exception e) {
          System.out.println(e.getMessage());
      }
  }
  
  }
  
  public class Google implements Serializable {
  
  private static final long serialVersionUID = 1L;
  
  private static Pattern patternDomainName;
  private Matcher matcher;
  private static final String DOMAIN_NAME_PATTERN = "([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,6}";
  static {
      patternDomainName = Pattern.compile(DOMAIN_NAME_PATTERN);
  }
  
  public void Searching(String searchstring) throws IOException {
  
      Google obj = new Google();
      Set&lt;String&gt; result = obj.getDataFromGoogle(searchstring);
      for (String temp : result) {
  
          if (temp.contains(searchstring)) {
              System.out.println(temp + " ----&gt; CONTAINS");
          } else {
              System.out.println(temp);
          }
      }
      System.out.println(result.size());
  
  }
  
  public String getDomainName(String url) {
  
      String domainName = "";
      matcher = patternDomainName.matcher(url);
      if (matcher.find()) {
          domainName = matcher.group(0).toLowerCase().trim();
      }
      return domainName;
  
  }
  
  private Set&lt;String&gt; getDataFromGoogle(String query) {
  
      Set&lt;String&gt; result = new HashSet&lt;String&gt;();
      String request = "https://www.google.com/search?q=" + query;
      System.out.println("Sending request..." + request);
  
      try {
  
          // need http protocol, set this as a Google bot agent :)
          Document doc = Jsoup.connect(request)
                  .userAgent("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)").timeout(6000)
                  .get();
  
          // get all links
          Elements links = doc.select("a[href]");
          for (Element link : links) {
  
              String temp = link.attr("href");
              if (temp.startsWith("/url?q=")) {
                  // use regex to get domain name
                  result.add(getDomainName(temp));
              }
  
          }
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      return result;
  }
  </code></pre>
  
  <p>}</p>