Google Suggest – Script php (Nouvelle version)
Ecrit par admin le Mercredi 27 janvier 2010 à 14:25 - Catégorie Google,Scripts PHP
Il y a quelques jours, nous vous présentions un outil nommé Google Suggest php script permettant d’extraire les suggestions proposées par Google à partir d’un mot-clé, les résultats ainsi obtenus étaient à nouveau extraits et ainsi de suite selon le niveau de profondeur défini par l’utilisateur du script (jusqu’à 5 niveaux).
Et bien, aujourd’hui nous vous proposons en plus les options suivantes :
- Gestion de listes de mots
- Intégration de mots mixés
- Test de mots + lettres de l’alphabet
- Récupération du nombre de résultats
Voici le script php google suggest nouvelle version :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | <?php //Script Google Suggest by http://www.seoblackout.com // Auteurs du script : Beunwa http://divioseo.fr/ & Tiger http://www.seoblackout.com // Contributeurs émérites : Seg http://www.wagablog.com/ & Meuhsli http://www.thugeek.com/ // Url article du script pour bugs, commentaires... : http://www.seoblackout.com/2010/01/27/google-suggest/ ?> <form action="" method="post"> <table><tr><td> Keyword : <textarea name="kw" rows="10"><?=strip_tags($_POST['kw'])?></textarea> </td><td> et <textarea name="mix2" rows="10"><?=strip_tags($_POST['mix2'])?></textarea> </td><td> <br /> Langue : <select name="lang"> <option value="fr">FR</option> <option value="en">EN</option> </select> <br /> Profondeur : <select name="depth"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <br /> Alphabet :<input type="checkbox" name="alph" /> </td></tr></table> <br /> <input type="submit" value="Go" /> </form> <?php if(isset($_POST['kw'])){ $lang = strip_tags($_POST["lang"]); if($lang == '') $lang = "fr"; $depth = strip_tags($_POST["depth"]); if($depth == '') $depth = "1"; $kwsd = array(); $kwsd=explode("\n",trim(strip_tags($_POST["kw"]))); foreach ($kwsd as $lst) { if($lst != "\n"){ //mots cles simple ggSuggest($lst, $lang, $depth); //mots cles avec compléments $kws2 = array(); $kws2=explode("\n",strip_tags($_POST["mix2"])); foreach ($kws2 as $mix2) { ggSuggest($lst.$mix2, $lang, $depth); } //alphabet if(strip_tags($_POST["alph"]) == "on"){ $alpha = "a"; while($alpha != "z"){ ggSuggest($lst.' '.$alpha, $lang, $depth); $alpha = ++$alpha; } } } } } function ggSuggest($kw, $lang, $depth = 1, $inc = 1){ global $tabKw; $tabKw[] = $kw; $url = 'http://www.google.com/complete/search?hl='.$lang.'&js=true&qu='. urlencode($kw); if (function_exists('curl_init')) { $header = array( "Accept: text/xml,application/xml,application/xhtml+xml, text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "Accept-Language: fr-fr,fr;q=0.7,en-us;q=0.5,en;q=0.3", "Accept-Charset: utf-8;q=0.7,*;q=0.7", "Keep-Alive: 300"); $ch = curl_init(); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com/'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)' ); curl_setopt($ch, CURLOPT_HTTPHEADER, $header ); curl_setopt($ch, CURLOPT_URL, $url); $result=curl_exec ($ch); curl_close ($ch); } else { $result= file_get_contents($url); } preg_match_all('/\["(.*?)",/si', $result, $kwgoogle, PREG_SET_ORDER);//mot preg_match_all('/\,"(.*?)résultats",/si', $result, $nbresult, PREG_SET_ORDER);//nb resultats if ($kwgoogle=='' || $inc > $depth) { return $tabKw; }else { $ii = 0; foreach($kwgoogle as $v){ $tk = utf8_decode(strip_tags($v[1])); if(!in_array($tk, $tabKw)){ $tk = str_replace ('\r',"", $tk); $kwr = utf8_decode($nbresult[$ii][1]); if($kwr == "") $kwr = 0; echo $kwr.' ; '.$tk.'<br />'; $ii++; flush(); ggSuggest($tk, $lang, $depth, $inc+1); } } } return $tabKw; } ?> |
Un grand merci à Seg (Wagablog – Google Analytics) et Meuhsli (Blog Geek) de l’agence référencement Résoneo, qui nous proposent ici une contribution majeure.
Merci encore une fois à Beunwa (Référencement Dijon), pour avoir contribué au développement du script Google Suggest.
Merci à eux 3 pour avoir accepté de partager publiquement et gratuitement avec vous ces améliorations !
Le web est un lieu de partage, keep this spirit !
A lire à propos de Google Suggest chez copains :
Commentaires (26)
Catégorie: Google,Scripts PHP
- Ajouter cet article à :
- Del.icio.us -
- Digg


