Different answers between Google site and Google API

I am trying to write JAVA code to get answers from Google. The code I write only works fine in English, but when I try to add some Hebrew characters, the answers I get are different than when I write it on the Google website.
Here is the code:

String address = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="; String charset = "UTF-8"; URL url; try { url = new URL(address + URLEncoder.encode(artistAndSong + site, charset)); //The url seems right, and it the same as the url that appear on the web Reader reader = new InputStreamReader(url.openStream(), charset); GoogleResults results = new Gson().fromJson(reader, GoogleResults.class); res =(results.getResponseData().getResults().get(0).getUrl()); //This is the part where I see that the answers are not the same } class GoogleResults{ private ResponseData responseData; public ResponseData getResponseData() { return responseData; } public void setResponseData(ResponseData responseData) { this.responseData = responseData; } public String toString() { return "ResponseData[" + responseData + "]"; } static class ResponseData { private List<Result> results; public List<Result> getResults() { return results; } public void setResults(List<Result> results) { this.results = results; } public String toString() { return "Results[" + results + "]"; } } static class Result { private String url; private String title; public String getUrl() { return url; } public String getTitle() { return title; } public void setUrl(String url) { this.url = url; } public void setTitle(String title) { this.title = title; } public String toString() { return "Result[url:" + url +",title:" + title + "]"; } } } 

Does anyone have an Idea? I’ve been trying to solve this for a couple of days ... (Also, I tried to play with Unicode, but it didn't seem to solve it.)
Thanks!

+4
source share
3 answers

Google responses are personalized based on your previous searches. Try to find the same when logging into your account, and when you are not logged in (try the incognito window if you use Chrome, for example), and the results should be different.

I think what is happening to you.

There are no obvious flaws in your code.

+6
source

You may encounter one or more of the following conditions:

  • As @darijan said: when are you logged in or not
  • Cookies are already present or not
  • Maybe some UserAgent discrimination
  • As Google gradually advances its algorithms, we can assume that the search API does not use the same version as the website.
0
source

Google Api retrieves results that are very different from results obtained using the Google website. This is widely known in the "world of SEO." This is very sad because this is the main reason that people working on SEO write their own crawlers. These programs make requests to the Google Website instead of the Google Api. Have you ever seen captcha on Google Search? Is the Google Search site blocked with a message like "We detected automatic traffic from your network. Contact your Internet provider." If Google will get the same results on the website and on the api, then the SEO companies will stop cheating on their site in order to get the right results.

So the answer is There is no bug in your code - this is Google fault.

0
source

Source: https://habr.com/ru/post/1486075/


All Articles