A voir également:
- Recuperer les resultat dune recherche google
- Dns google - Guide
- Google maps satellite - Guide
- Google recherche par image - Guide
- Google earth - Télécharger - 3D
- Recherche musique - Guide
4 réponses
goldmann
Messages postés
1
Date d'inscription
vendredi 29 avril 2011
Statut
Membre
Dernière intervention
29 avril 2011
1
29 avril 2011 à 00:28
29 avril 2011 à 00:28
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];
}
?>