Recuperer les resultat dune recherche google
gwalchmai22
-
Nyini -
Nyini -
Bonjour,
je dois réaliser un programme qui me permet de récupérer les résultats d'une recherche Google dans un fichier xml (enfin normalement).
le but final est d'avoir un programme qui me permet de rentrer une recherche et d'obtenir les résultats de la recherche ,qui aura était faite sur Google, sur une autre page web.
j'aimerai récupérer les description du site de la recherche Google, plus son adresse mais je ne vois pas comment faire pour récupérer ces données.
pourriez vous m'éclairer sur la demarche a suivre pour arriver a obtenir le resultat souhaiter??
merci de votre aide
bonne soirée
je dois réaliser un programme qui me permet de récupérer les résultats d'une recherche Google dans un fichier xml (enfin normalement).
le but final est d'avoir un programme qui me permet de rentrer une recherche et d'obtenir les résultats de la recherche ,qui aura était faite sur Google, sur une autre page web.
j'aimerai récupérer les description du site de la recherche Google, plus son adresse mais je ne vois pas comment faire pour récupérer ces données.
pourriez vous m'éclairer sur la demarche a suivre pour arriver a obtenir le resultat souhaiter??
merci de votre aide
bonne soirée
A voir également:
- Recuperer les resultat dune recherche google
- Google maps - Guide
- Google maps satellite - Guide
- Google photo - Télécharger - Albums photo
- Dns google - Guide
- Comment récupérer les messages supprimés sur whatsapp - Guide
4 réponses
bonjour
voici mon code php dont tab contient la resultat du recherche google sur le mot clé sport le mot clé sport est introduit dans la variable $a
<?php
$a='sport';
$target_url = 'http://www.google.com/search?q='.$a ;
$userAgent = 'Googlebot/2.1 (https://developers.google.com/search/docs/advanced/crawling/googlebot?visit_id=637428413923342000-4066939882&rd=1
//$userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html = curl_exec($ch);
if (!$html) {
echo "cURL error number:" . curl_errno($ch);
echo "cURL error:" . curl_error($ch);
exit;
}
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a[contains(@class,'l')]");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
$tab[$i] = $url;
}
$h = count($tab);
$res = 0;
for(i=$i;$i<$h ;$i++){
echo tab[$i];
}
?>
voici mon code php dont tab contient la resultat du recherche google sur le mot clé sport le mot clé sport est introduit dans la variable $a
<?php
$a='sport';
$target_url = 'http://www.google.com/search?q='.$a ;
$userAgent = 'Googlebot/2.1 (https://developers.google.com/search/docs/advanced/crawling/googlebot?visit_id=637428413923342000-4066939882&rd=1
//$userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html = curl_exec($ch);
if (!$html) {
echo "cURL error number:" . curl_errno($ch);
echo "cURL error:" . curl_error($ch);
exit;
}
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a[contains(@class,'l')]");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
$tab[$i] = $url;
}
$h = count($tab);
$res = 0;
for(i=$i;$i<$h ;$i++){
echo tab[$i];
}
?>