par
gillescoste2006 » 29 nov. 2019, 13:25
Bonjour,
Pour un devoir, j'ai besoin de scrapper Wikipédia
J'ai trouvé ce script pour scrapper les h1
Code : Tout sélectionner
<?php
//get the html returned from the following url
$html = file_get_contents('https://fr.wikipedia.org/wiki/Anaconda,_le_prédateur');
//init DOMDocument
$scriptDocument = new DOMDocument();
//disable libxml errors
libxml_use_internal_errors(TRUE);
//check if any html is actually returned
if(!empty($html)){
//loadHTML
$scriptDocument->loadHTML($html);
//clear errors for yucky html
libxml_clear_errors();
//init DOMXPath
$scriptDOMXPath = new DOMXPath($scriptDocument);
//get all the h1's
$scriptRow = $scriptDOMXPath->query('//h1');
//check
if($scriptRow->length > 0){
foreach($scriptRow as $row){
echo $row->nodeValue . "<br/>";
}
}
}
?>
Ce script fonctionne pour scrapper 1 url.
Mais j'ai besoin de scrapper un liste d'url à savoir
https://fr.wikipedia.org/wiki/Anaconda,_le_prédateur
https://fr.wikipedia.org/wiki/Eunectes_murinus
https://fr.wikipedia.org/wiki/Eunectes
Comment dois-je modifier le script pour prendre en compte plusieurs url de wiki
Merci pour votre aide
Bonjour,
Pour un devoir, j'ai besoin de scrapper Wikipédia
J'ai trouvé ce script pour scrapper les h1
[code]<?php
//get the html returned from the following url
$html = file_get_contents('https://fr.wikipedia.org/wiki/Anaconda,_le_prédateur');
//init DOMDocument
$scriptDocument = new DOMDocument();
//disable libxml errors
libxml_use_internal_errors(TRUE);
//check if any html is actually returned
if(!empty($html)){
//loadHTML
$scriptDocument->loadHTML($html);
//clear errors for yucky html
libxml_clear_errors();
//init DOMXPath
$scriptDOMXPath = new DOMXPath($scriptDocument);
//get all the h1's
$scriptRow = $scriptDOMXPath->query('//h1');
//check
if($scriptRow->length > 0){
foreach($scriptRow as $row){
echo $row->nodeValue . "<br/>";
}
}
}
?> [/code]
Ce script fonctionne pour scrapper 1 url.
Mais j'ai besoin de scrapper un liste d'url à savoir
https://fr.wikipedia.org/wiki/Anaconda,_le_prédateur
https://fr.wikipedia.org/wiki/Eunectes_murinus
https://fr.wikipedia.org/wiki/Eunectes
Comment dois-je modifier le script pour prendre en compte plusieurs url de wiki
Merci pour votre aide