1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
<?php
// Le texte recherché
$search = "test";
// Url de la page à traiter
$url = "http://www.mediatheque-agglo-sgms.fr/opacwebaloes/index.aspx?IdPage=49";
// Récupération du __viewstate
$recupviewstate = file_get_contents($url);
preg_match_all("/name=\"__VIEWSTATE\" value=\"(.*?)\"/", $recupviewstate, $arr_viewstate);
$viewstate = $arr_viewstate[1][0];
$postfields = array();
$postfields["__VIEWSTATE"] = $viewstate;
$postfields["_ctl0:_ctl3:_ctl0:Critere_82_406_num:txtSaisie1"] = urlencode($search);
$useragent = "Mozilla/5.0";
$referer = $url;
// Initialisation d'une session cURL
$ch = curl_init($url);
// Options cURL
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// ASP.NET_SessionId
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
// Execution
$result = curl_exec($ch);
curl_close($ch);
// Affichage
echo $result;
?> |
Partager