Bonjour,

J'ai créé un script php pour aller chercher des informations sur le site de ma banque (hsbc).

L'ennui c'est que le site est assez compliqué, avec pas mal de javascript dans les formulaires... J'ai réussi à poster mes identifiant, mais après il y a plusieurs redirections et je suis un peu perdu... Quelqun pourrait-il m'aider à y voir clair ?

Merci beaucoup :)

Pour tester, la page de connexion est https://www.hsbc.fr/1/2/hsbc-france/particuliers/connexion
mon id est 33713624011

<?php 
    //URL de départ
    $url = 'https://www.hsbc.fr/1/2/hsbc-france/particuliers/connexion';

$path_cookie = 'connexion_bq_hs.txt';
if (!file_exists(realpath($path_cookie))) touch($path_cookie);

// Je lis la première adresse où envoyer mon id en avec une requête post : 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_COOKIESESSION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_COOKIEJAR, realpath($path_cookie));
    $result = curl_exec($ch);
    //print_r($result); 

    //close connection
    //curl_close($ch);

//Rechercher l'adresse où poster l'id :

$regex = '/<form name="auth" id="idv_auth_form" method="post" autocomplete="off" action="(.*?)">/s';

// Je fais juste un petit test pour afficher le lien où poster l'id

if ( preg_match_all($regex, $result, $list)) {
   echo('</br>');
   echo('Lien trouvé');
   echo('</br>');
   echo('</br>');
   }

else 
    print "Not ok"; 

//poster les id utilisateur sur le lien identifié :

$url2 = 'https://www.hsbc.fr/'.$list[1][0];

// il y a plusieurs ids à poster, je les ai mis dans la variable $postfields : 
$postfields = array(
    '__hbfruserid' => '33713624011',
    'cookieuserid' => 'false',
    'nextPage' => 'localsso.hbfr.Redirect',
    'userid' => '33713624011',
);

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url2);

        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_COOKIESESSION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_COOKIEJAR, realpath($path_cookie));
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
        curl_setopt($ch, CURLOPT_COOKIEJAR, realpath($path_cookie));
    $result = curl_exec($ch);
    //print_r($result); 
    //curl_close($ch);

// Je recherche le deuxième lien pour la page avec les mots de passe : 
$regex = '#Location: (.*?)\r#';

if ( preg_match_all($regex, $result, $list, PREG_OFFSET_CAPTURE)) {
   echo('Deuxième lien : ');
   echo('</br>');
   print_r($list[1][0][0]);
   echo('</br>');
   }

else 
    print "Not ok";

// Afficher la page de connexion : 

$url3 = $list[1][0][0];

echo $url3;
   echo('</br>');
   echo('</br>');
   echo('__');
   echo('</br>');
   echo('</br>');

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url3);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_COOKIESESSION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($ch, CURLOPT_COOKIEJAR, realpath($path_cookie));
    $result = curl_exec($ch);
    print_r($result); 

    //close connection
    //curl_close($ch);

?>

1 réponse


Guzzle ;)
lien