2017-08-15 4 views
0

je dois gratter cette page HTML ...Obtenez Xpath pour les éléments HTML de la page Web .asp

http://www.asl1.liguria.it/templateProntoSoccorso.asp

enter image description here

.... en utilisant PHP et XPath pour obtenir les valeurs comme 2

Codice bianco:

(NOTE: vous pouvez voir la valeur différente s dans cette page si vous essayez de le parcourir ... il n'a pas d'importance .. ,, ils changent dinamically ....)

Je ne peux pas obtenir le XPath pour ces valeurs en utilisant Mozilla Firebug comme d'habitude je faire: des suggestions?

Merci d'avance!

MISE À JOUR

<?php 
    ini_set('display_errors', 1); 

    $url = 'http://www.asl1.liguria.it/templateProntoSoccorso.asp'; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
    curl_setopt($ch, CURLOPT_PROXY, ''); 
    $data = curl_exec($ch); 
    curl_close($ch); 

    $dom = new DOMDocument(); 
    @$dom->loadHTML($data); 

    $xpath = new DOMXPath($dom); 

    $Number = $xpath->query('/html/body/table/tbody/tr/td[2]/table[2]/tbody/tr/td[3]/table/tbody/tr[2]/td[1]/table/tbody/tr/td/div[1]/div[3]/div[2]'); 

    foreach($Number as $node) 
    { 
     echo "Number: " .$node->nodeValue; 
     echo '<br>'; 
     echo '<br>'; 
    }  
?> 
+0

Notez que [le développement de Firebug est arrêté] (https://hacks.mozilla.org/2016/12/firebug-lives-on-in-firefox-devtools/) en faveur des outils de développement intégrés de Firefox. –

Répondre

0

Je l'ai résolu ... ici vous êtes le bon code

<?php 
    ini_set('display_errors', 1); 

    $url = 'http://www.asl1.liguria.it/templateProntoSoccorso.asp'; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
    curl_setopt($ch, CURLOPT_PROXY, ''); 
    $data = curl_exec($ch); 
    curl_close($ch); 

    $dom = new DOMDocument(); 
    @$dom->loadHTML($data); 

    $xpath = new DOMXPath($dom); 

    $Number = $xpath->query('(//div[@class="datiOspedaleCodici"]/div[1]/text())[1]'); 

    foreach($Number as $node) 
    { 
     echo "Number: " .$node->nodeValue; 
     echo '<br>'; 
     echo '<br>'; 
    }  
?> 

que print ....

Codice bianco: 2

1

Cela devrait fonctionner:

  1. Valeur de Premier élément:

    substring-after(//div[@class="datiOspedaleCodici"]/div[1]/text(), ":") 
    
  2. De seconde:

    substring-after(//div[@class="datiOspedaleCodici"]/div[2]/text(), ":") 
    

    ... etc

Juste augmenter indice /div[x] pour obtenir la prochaine valeur

+0

J'ai mis à jour ma question initiale avec un code PHP dans lequel j'ai essayé d'utiliser le xPath (complet), mais cela ne fonctionne pas .... – Cesare