Skip to content

Instantly share code, notes, and snippets.

@titomus
Created Feb 13, 2022
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