Récuperer le contenu d'une page web en php

Bonjour,

je souhaite récuperer la ligne du resultat d'un joueur sur ce site http://xwis.net/ra2/pl/goodbye/ a l'aide de php avez vous une idée de comment je peut procéder. Merci.

4 réponses

  1. Modérateur
    Tu peux déjà commencer par récupérer la page en vue de l'analyser. J'utilise ici cURL:cURL
    Malheureusement mon proxy ne semble pas fonctionner...
    J'ai ajouté des sauts de lignes afin d'obtenir une page HTML lisible pour l'humain.
    Par contre, c'est de très loin un document XML conforme (au sens large). Il faudra tripatouille pour extraire les données, puisque ce document ne sera pas analysé correctement par les outils XML standards.
    johand@osiris: ~/src/CCM/php $ cat get_xwis_data.php 
    <?php 
    $URL="http://xwis.net/ra2/pl/goodbye/"; 
    $XML_DATA = "data.xml"; 
    
    function get_data($url, &$page_content, $xml_file) 
    { 
      $timeout = 10; 
      $proxy_host = 'http://192.168.0.8'; // host 
      $proxy_port = 3128; 
      $proxy_ident = ''; // username:password 
    
      $ch = curl_init($url); 
    
      curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 
      curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
    
      if (preg_match(''^[https:// https://'i',] $url)) 
        { 
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
        } 
    
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    
    
    
      // Activation de l'utilisation d'un serveur proxy 
      curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false); 
      // Définition de l'adresse du proxy 
      curl_setopt($ch, CURLOPT_PROXY, $proxy_host); 
      curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port); 
      // Définition des identifiants si le proxy requiert une identification 
      if ($proxy_ident) 
        { 
          curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_ident); 
        } 
    
      curl_setopt($ch, CURLOPT_ENCODING , "gzip"); 
      $headers_enabled = 0; 
      curl_setopt($ch, CURLOPT_HEADER, $headers_enabled); 
    
      $page_content = curl_exec($ch); 
      curl_close($ch); 
      $handle = fopen($xml_file, "w"); 
      fwrite($handle, $page_content); 
      print("HERE"); 
      fclose($handle); 
    } 
    
    $page_content=""; 
    
    if( file_exists($XML_DATA)) 
      { 
        $handle = fopen($XML_DATA, "r"); 
        if ( $handle ) 
          { 
     $page_content = fread($handle, filesize($XML_DATA)); 
          } 
      } 
      else 
        { 
          get_data($URL, $page_content, $XML_DATA); 
        } 
    
    // preg_lace ( mixed $pattern , mixed $replacement , mixed $subject ) 
    $page_content = preg_replace('!<!im' ,"\n<", $page_content); 
    $page_content = preg_replace('!>!im' , ">\n", $page_content); 
    echo $page_content; 
    ?>

    Gates gave ^H sold you the windows.
    GNU gave us the whole house.(Alexandrin)
    0
    1. non car je souhaite réafficher le resultat sur une page web
      0
      1. Une simple capture d'écran peu peut-être t'aider non ?
        0