开发者

Getting real Google results in Google AJAX API

开发者 https://www.devze.com 2023-01-06 18:29 出处:网络
When i perform a search I using the Google AJAX API (http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=flowers&gl=fr)

When i perform a search I using the Google AJAX API (http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=flowers&gl=fr)

(with gl=fr) the first found URL is : flowercampings.com.

whereas when I use google.fr, the first link is : www.1800flowers.com

How I can get the same results using the API (I need the REST开发者_JS百科interface parameters) Thanks for helping


you can't.

there are no "real" results.

a SERP (search engine result page) you see != a SERP someone else sees because a sh*tload of factors some into account (location, your web history, pervious searches, logged in, logged out, time of day, .... )

and yes, the API is known to not display same results as the google search page (some say it's an older google index, i think it's just different), but then again if the person next to you searches from his computer, he might also see another SERP.

the only way to get the same results you see would be installing a programmable browser on your machine and then scrap the results and make your own JSON out of it. but that's probably not what you want.


Almost Search Engines base on your personal info (location, nation, language, history, search behave/trend,...) to calculate result page, this is reason.


We've built a solution that run a full browser to fetch results that are the closest possible to what actual user see: https://serpapi.com

We have integreations in several languages. Python:

from lib.google_search_results import GoogleSearchResults
query = GoogleSearchResults({"q": "coffee"})
html_results = query.get_html()

GitHub: https://github.com/serpapi/google_search_results_python

Java:

Map<String, String> parameter = new HashMap<>();
parameter.put("q", "Coffee");
parameter.put("location", "Portland");
parameter.put(GoogleSearchResults.SERP_API_KEY_NAME, "demo");
GoogleSearchResults serp = new GoogleSearchResults(parameter);

JsonObject data = serp.getJson();
JsonArray results = (JsonArray) data.get("local_results");
JsonObject first_result = results.get(0).getAsJsonObject();
System.out.println("first coffee: " + first_result.get("title").getAsString());

GitHub: https://github.com/serpapi/google_search_results_java

And Ruby:

require 'google_search_results'
query = GoogleSearchResults.new q: "coffee"
hash_results = query.get_hash

GitHub: https://github.com/serpapi/google-search-results-ruby

0

精彩评论

暂无评论...
验证码 换一张
取 消