Last active
May 7, 2020 22:19
-
-
Save vivirenremoto/b5349ae289129be609f7c62d686bf88d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ejemplo de uso | |
// https://dominio/keywords_google.php?search=lavadoras&lang=es | |
// resultados para la keyword lavadoras | |
// https://gist.github.com/vivirenremoto/e6373a847903501b8d2b07b6e658feab | |
function get_curl($url){ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_TIMEOUT,60); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_ENCODING, ''); | |
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
$response = curl_exec($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
return $response; | |
} | |
function get_suggestions($search, $lang){ | |
$url = "http://suggestqueries.google.com/complete/search?output=firefox&hl=" . $lang . "&q=" . urlencode($search); | |
$json = json_decode( get_curl($url) ); | |
return $json[1]; | |
} | |
$search = $_GET['search']; | |
$lang = isset($_GET['lang']) ? $_GET['lang'] : 'es'; | |
$keywords = array(); | |
$json1 = get_suggestions($search, $lang); | |
foreach( $json1 as $value1 ){ | |
$keywords[] = $value1; | |
$json2 = get_suggestions($value1, $lang); | |
foreach( $json2 as $value2 ){ | |
$keywords[] = $value2; | |
$json3 = get_suggestions($value2, $lang); | |
foreach( $json3 as $value3 ){ | |
$keywords[] = $value3; | |
$json4 = get_suggestions($value3, $lang); | |
foreach( $json4 as $value4 ){ | |
$keywords[] = $value4; | |
} | |
} | |
} | |
} | |
$keywords = array_unique($keywords); | |
sort($keywords); | |
echo '<b>' . count($keywords) . ' keywords</b><br>'; | |
foreach( $keywords as $keyword ){ | |
echo $keyword . '<br>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment