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
|
$store = array();
foreach($response3 as $search)
{
$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"]');
foreach($items as $item)
{
$var = str_replace(html_entity_decode(' ', null, 'utf-8'), '', trim($item->lastChild->nodeValue));
sscanf($var, '%D', $store[$search][]);
}
}
//jusque la ca fonctionnes mon store est bien un tableau associatif avec en [0] et [1] les données que je veux
foreach($store as $search => $result)
{
$q=urlencode($search);
$search_url="http://www.google.com/search?q=$q&hl=fr&tbo=1&tbs=ww:1";
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTMLFile($url);
libxml_clear_errors();
$xpath = new DOMXPath($doc);
$items = $xpath->query('//*[@id="resultStats"]');
// $store[$search][3]= $item;
foreach($items as $item)
{
$text = filter_var($item->nodeValue, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
sscanf($text, '%D', $store[$search][]);
}
}
//cette partie du dessus ne fonctionne pas du tout j ai essayez plein de chose avec / sans for each etc bref j ai rien dans le [3] je pense que ca viens du trim mon soucis
//google api
foreach($store 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);
$store[$search][4] = $json-> responseData-> cursor-> estimatedResultCount;
}
//cette partie fonctionne bien , c est l équivalent en utilisant l api que propose google mais malheuresement les résultats sont trèèèèèèèsss loin de la réalité |
Partager