Tuesday 15 July 2014

java - Page that programmatically is taken is different than normal google page? -


We want to programmatically present the current Google page. We use many technologies with different programmatic languages ​​but we do not get to get the right (current) Google page

Java code example

  public class GoogleParser {Public static zero main (string [] args) {GoogleParser googleParser = new GoogleParser (); Googleprarser.execute (); } Execute Public Zero () {string [] Parameters = {"Ankara Knifsu"}; Final URL url = encoding GoogleQuery (parameter); Downloading system.out.println ("[" + url + "] ... \ n \ n \ n \ n \ n"); {Try the final string html = downloadString (url); Println (html); } Grip (IOException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); }} Private String String download string throws (last input stream stream) IOException {Last BitReon Output Stream Out = New Bytereon Output Stream (); Int ch; While (-1! = (Ch = stream.read ())) out.write (ch); Return out.trusting (); } Private String String download string throws IOException (final URL url) {Final string agent = "Mozilla / 21.0 (Windows; U; Windows 7; N-US)"; Final URL Connection Connection = url.openConnection (); Connection.setRequestProperty ("user-agent", agent); Last input stream stream = connection.getInputStream (); Return DownloadString (Stream); } Private static url codename GoogleQuery (last string [] args) {try {final stringbiller localAddress = new StringBuilder (); LocalAddress.append ("/ search? Q =?"); {Final string encoding = url encoder for (int i = 0; i & lt; args.length; i ++) Encoded (RGS [i], "UTF-8"); LocalAddress.append (encoding); If (i + 1 & lt; args.length) localAddress.append ("+"); } Return new URL ("http", "www.google.com", localAdration.string ()); } Hold (last IOException E) {// Errors should not be under normal circumstances Throw new runtime up ("Error occurred during the query argument encoding."); }}}   

Java code gets this html page Google current page

  first image java code result page second image google current page   

The HTML page that meets Java, is different from the current Google page.

  • The results of the Google results are not included (4,551 milyon (2011))
  • Google article results not included (Ankara information on the right)
  • Current page
  • New properties (web, mage, video) on the left side, usually below the search bar below

    Do you have any Consider how to get Google's current (final) page with programmatically Java language, though to solve the problem, The solutions are important

    Thanks for your response

    Smart

    1. Make sure that you send cookies similar to your browser
    2. Make sure you send the same or valid browser agent string

  • No comments:

    Post a Comment