Google Search API

I was wondering if any of you know how to implement a backend system that will receive SEO information from Google (website ranking, #ocurrences in the first X results on google, etc.).

I know that the Google AJAX search API (code.google.com/apis/ajaxsearch/) will allow you to retrieve content without having to "wget" or "curl", but using the search information does not seem legal (code.google.com/apis/ ajaxsearch / terms.html).

Any ideas on how to implement this?

+4
source share
3 answers

I researched how to do this with Google, and AFAICT really has no way to do this legally. Since their cash cow is those extraditions, they do not allow anyone to scratch them for any reason.

There are many services that will scratch Google for you, but from what I can say, they all do it against Google TOS. If you figure out a way to do this legally, let me know. I guess there are a few who scratch with the permission granted, but I'm not sure who they are.

The only ideas I have had so far are:

  • Set up a "proxy server" that is used to automate requests from Google clients. Then the proxy server can see the results and make scrapers, and this is not "automated". If the user enters 20 terms, then open the 20 frames that search through the proxy server.
  • Piggyback on web traffic coming to the site. In short: I visit your site, and a background JavaScript call searches Google and publishes the results on your site. This is unethical, as I may wonder why “your” searches appear in my Google history.

The problem is "automated." I have the feeling that those services that actually have computer farms around the world so that they appear (on Google) that they are not being cleaned up. I assume that if you do not start generating some serious traffic from one IP address, you will be fine for a while.

Perhaps you should just ask permission?

+2
source

There is http://toolbarqueries.google.com that the Google toolbar uses (or is used to use) to get PageRank for links. It can be easily requested by hashing the URLs first for validation in the specified format.

AFAIK is an undocumented API and, as such, is unclear what the legal consequences of using it are.

Regards, DrSlump

0
source

Create the querygoogle.php file in the same folder:

 <?php session_start(); // Here the Google AJAX Search API url for curl. It uses Google Search site:www.yourdomain.com syntax to search in a specific site. I used $_SERVER['HTTP_HOST'] to find my domain automatically. Change $_POST['searchquery'] to your posted search query $url = 'http://ajax.googleapis.com/ajax/services/search/web?rsz=large&v=1.0&start=20&q=' . urlencode('' . $_POST['searchquery']); // use fopen and fread to pull Google search results $handle = fopen($url, 'rb'); $body = ''; while (!feof($handle)) { $body .= fread($handle, 8192); } fclose($handle); // now $body is the JSON encoded results. We need to decode them. $json = json_decode($body); // now $json is an object of Google search results and we need to iterate through it. foreach($json->responseData->results as $searchresult) { if($searchresult->GsearchResultClass == 'GwebSearch') { $formattedresults .= ' <div class="searchresult"> <h3><a href="' . $searchresult->unescapedUrl . '">' . $searchresult->titleNoFormatting . '</a></h3> <p class="resultdesc">' . $searchresult->content . '</p> <p class="resulturl">' . $searchresult->visibleUrl . '</p> </div>'; } } $_SESSION['googleresults'] = $formattedresults; header('Location: ' . $_SERVER['HTTP_REFERER']); exit; ?> 

And create another search.php file in the same folder:

 <?php session_start(); ?> <form method="post" action="querygoogle.php"> <label for="searchquery"><span class="caption">Search this site</span> <input type="text" size="20" maxlength="255" title="Enter your keywords and click the search button" name="searchquery" /></label> <input type="submit" value="Search" /> </form> <?php if(!empty($_SESSION['googleresults'])) { echo $_SESSION['googleresults']; unset($_SESSION['googleresults']); } ?> 

Press the search button, and the result will be printed using the echo $_SESSION['googleresults'];

0
source

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


All Articles