【发布时间】:2012-11-19 16:39:13
【问题描述】:
如何从这段代码中提取sessionId 和viewstate 变量?
代码是这样的:
$url = "http://www.atb.bergamo.it/ITA/Default.aspx?SEZ=2&PAG=38&MOD=LINTRV";
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec ($ch);
curl_close($ch);
preg_match('~<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.*?)" />~',$html,$viewstate);
var_dump(file_get_contents($ckfile)); //<--- There's the sessionId variable in it
var_dump($viewstate[1]); //<--- View State
你能帮帮我吗?
【问题讨论】:
-
使用 HTML 解析器提取这些值比使用正则表达式更容易。然而,对于正则表达式,这已经被问过并回答过。