How do I get the same results I have in common Google Search, via the Google Search Api?

Asked

Viewed 652 times

1

When I search Chris Brown through the api I get these results:

inserir a descrição da imagem aqui

But in Google search by browser the results are different:

inserir a descrição da imagem aqui

Assumptions:

  • Through the site search, even if I am not logged in, the search occurs based on some additional information extracted from the browser. Ip and language, for example...
  • Thinking about this way I imagined that maybe there could be parameters that allow me to use the api in the same way as the browser.

Does anyone have any deeper idea of each other’s search differences and how I can make them equal or similar?

Code:

<?php
    $query = urlencode('Chris Brown');
    $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=".$query;
    $body = file_get_contents($url);
    $json = json_decode($body);


    for($x=0; $x < count($json->responseData->results); $x++){
        echo "<b>Resultado ".($x+1)."</b>";
        echo "<br>URL: ";
        echo $json->responseData->results[$x]->url;
        echo "<br>VisibleURL: ";
        echo $json->responseData->results[$x]->visibleUrl;
        echo "<br>Título: ";
        echo $json->responseData->results[$x]->title;
        echo "<br><br>";
    }
?>
  • At the beginning of the question I can already see that it has something to do with localization. See if the API has any location/country/language settings/etc..

  • If possible put the API documentation link in the question.

2 answers

1


There is no way because I was using an old API to Google Web Seach API, which is obsolete.

I’ll switch to the current Google Custom Search API to try to get the results I need.

-1

I have a JS code that makes a request and returns the value obtained and by it use your browser to send the request it must have the same Google Search Results Code(requires jquery):

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
function searchGoogle(Query) {
// Seta A Variavel Final
final = {}
// Faz a Request Com o Cors-Anywhere Para Burlar A CORS-POLICY
shweb = $.ajax({url: 'https://cors-anywhere.herokuapp.com/' + "https://www.google.com/search?q=" + Query, async: false})
// Seta A Variavel Que Contem o HTML Da Pagina
shhtm = stringToHTML(shweb.responseText)
// Seta A Variavel Shres Com a Class 'LC20lb DKV0Md'
shres = shhtm.getElementsByClassName('LC20lb DKV0Md')
// Faz Um Loop Entre Os Links
for (i = 0; i < shres.length - 1; i++) {
// Seta O Final
final[i] = {href: shres[i].parentElement.href, title: shres[i].innerText, desc: shres[i].parentElement.parentElement.parentElement.children.item(1).innerText}
}
// Retorna O Valor Final
return final;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.