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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
| <?php
set_time_limit(0);
//choix de la recherche
if(ISSET($_GET['kw'])) $kw=$_GET['kw']; else $kw='google'; //mot clé
if(ISSET($_GET['alexa'])) $alexa=$_GET['alexa']; else $alexa=0;//alexa 1=oui 0=non
if(ISSET($_GET['adwords'])) $adwords=$_GET['adwords']; else $adwords=0; //api adwords 1 = oui 0= non
if(ISSET($_GET['wonderwheel'])) $wonderwheel=$_GET['wonderwheel']; else $wonderwheel=0; //roue magique
if(ISSET($_GET['ggsuggest'])) $ggsuggest=$_GET['ggsuggest']; else $ggsuggest=0; // google suggest
if(ISSET($_GET['gsearchapi'])) $gsearchapi=$_GET['gsearchapi']; else $gsearchapi=0; // google api search
if($kw=='google' && $alexa==0 && $ggsuggest==0 && $wonderwheel==0 && $gsearchapi==0){
print ("<script language = \"JavaScript\">");
print ("location.href = '?kw=mot%20clé&alexa=0&adwords=0&wonderwheel=0&ggsuggest=0&gsearchapi=0';");
print ("</script>");
}
$tableau=array();
if($wonderwheel) //wonderwheel
{
$kw=urlencode($kw);
$search_url="http://www.google.com/search?q=$kw&hl=fr&tbo=1&tbs=ww:1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.63 (Windows NT 5.1; U; fr) Presto/2.1.1');
curl_setopt($ch, CURLOPT_URL,$search_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_REFERER, $search_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$res= curl_exec($ch);
curl_close($ch);
if ($res) {
if (preg_match('/"r":\[(.*?)\]}\)/',$res,$matches))
{
$response=str_replace('"','',$matches[1]);
$response2=explode(',',$response);
$response3='';
foreach ($response2 as $key => $value)
{
$value2=urlencode($value);
$search_url2="http://www.google.com/search?q=$value2&hl=fr&tbo=1&tbs=ww:1";
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_USERAGENT, 'Opera/9.63 (Windows NT 5.1; U; fr) Presto/2.1.1');
curl_setopt($ch2, CURLOPT_URL,$search_url2);
curl_setopt($ch2, CURLOPT_FAILONERROR, true);
curl_setopt($ch2, CURLOPT_REFERER, $search_url2);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER,true);
$res2= curl_exec($ch2);
curl_close($ch2);
if ($res2)
{
if (preg_match('/"r":\[(.*?)\]}\)/',$res2,$matches2))
{
$response.=','.str_replace('"','',$matches2[1]);
}
}
}
$response3=array_unique(explode(',',$response));
asort($response3);
foreach ($response3 as $key => $value)
{
$tableau[str_replace(array('r2:','[',']','r2 '),'',$value)]=array();
flush();
}
}
}
}else $tableau[$kw]=array();
//var_dump($res_final);
if($ggsuggest) //google suggest
{
foreach($tableau as $key => $value)
{
$lang = "fr";
$url = 'http://www.google.com/complete/search?hl='.$lang.'&js=true&qu='. urlencode($key);
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
$tableau[$key]=array();
foreach ($kwgoogle as $kw)
$tableau[$kw[1]]=array();
}
}
if((!$ggsuggest)&&(!$wonderwheel))
$tableau[$kw]=array();
if($alexa) //alexa
foreach($tableau as $search => $value)
{
$j=0;
while((empty($tableau[$search]))&&(j<=3)){
$query = http_build_query(array('q' => $search, 'p' => 'qkey'));
$url = "http://www.alexa.com/search?$query";
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTMLFile($url);
libxml_clear_errors();
$xpath = new DOMXPath($doc);
$items = $xpath->query('//p[@class="qindex"]');
$i=0;
foreach($items as $item)
{
$var = str_replace(html_entity_decode(' ', null, 'utf-8'), '', trim($item->lastChild->nodeValue));
if($i==0) sscanf($var, '%D', $tableau[$search]['concurrence']);
else sscanf($var, '%D', $tableau[$search]['popularité']);
$i++;
}
}
}
if($gsearchapi)//google search api
{
foreach($tableau as $search => $result)
{
$value2=urlencode($search);
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=$value2&hl=fr";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.blog.neptis.info/page_referer.php");
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body);
$tableau[$search]['nbresultat'] = (int) $json-> responseData-> cursor-> estimatedResultCount;
}
}
if($adwords) //api adwords
{
$path = dirname(__FILE__) . 'application/aw/src';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'application/aw/src/Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
require_once 'application/aw/src/Google/Api/Ads/Common/Util/MapUtils.php';
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
// Log SOAP XML request and response.
$user->LogDefaults();
// Get the TargetingIdeaService.
$targetingIdeaService = $user->GetTargetingIdeaService('v200909');
foreach($tableau as $search => $value)
{
// Create seed keyword.
$keyword = new Keyword();
$keyword->text = 'mars cruise';
$keyword->matchType = 'BROAD';
// Create selector.
$selector = new TargetingIdeaSelector();
$selector->requestType = 'IDEAS';
$selector->ideaType = 'KEYWORD';
$selector->requestedAttributeTypes = array('KEYWORD', 'AVERAGE_TARGETED_MONTHLY_SEARCHES');
// Set selector paging (required for targeting idea service).
$paging = new Paging();
$paging->startIndex = 0;
$paging->numberResults = 10;
$selector->paging = $paging;
// Create related to keyword search parameter.
$relatedToKeywordSearchParameter = new RelatedToKeywordSearchParameter();
$relatedToKeywordSearchParameter->keywords = array($keyword);
// Create keyword match type search parameter to ensure unique results.
$keywordMatchTypeSearchParameter = new KeywordMatchTypeSearchParameter();
$keywordMatchTypeSearchParameter->keywordMatchTypes = array('BROAD');
$selector->searchParameters =array($relatedToKeywordSearchParameter, $keywordMatchTypeSearchParameter);
// Get related keywords.
$page = $targetingIdeaService->get($selector);
// Display related keywords.
if (isset($page->entries)) {
foreach ($page->entries as $targetingIdea) {
$data = MapUtils::GetMap($targetingIdea->data);
$keyword = $data['KEYWORD']->value;
$averageMonthlySearches =
isset($data['AVERAGE_TARGETED_MONTHLY_SEARCHES']->value)
? $data['AVERAGE_TARGETED_MONTHLY_SEARCHES']->value : 0;
$tableau[$kewyord->text]['averageMonthlySearches']=$averageMonthlySearches;
// printf("Keyword with text '%s', match type '%s', and average monthly "
// . "search volume '%s' was found.\n", $keyword->text,
// $keyword->matchType, $averageMonthlySearches);
}
}
}}
ksort($tableau);
var_dump($tableau);
?> |
Partager