Skip to content

Instantly share code, notes, and snippets.

@titomus
Created February 13, 2022 15:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Google Suggest scraper
<?php
function ggSuggest($word, $lang = 'fr', $spin = false){
$word = urlencode(trim($word));
$words = array();
$apicall = ("https://www.google.com/complete/search?output=toolbar&q=$word");
$result = utf8_encode(file_get_contents($apicall));
$resp = simplexml_load_string($result);
if ($resp){
foreach ($resp as $t) {
$words[] = $t->suggestion['data'];
}
return ($spin === true) ? '{' . implode('|', $words) . '}' : $words;
}
else{
return false;
}
}
//test
echo '<pre>';
var_dump(ggSuggest('referencement'));
echo '<hr/>';
echo (ggSuggest('seo', 'fr', true));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment