嗨,我编写了以下脚本来登录网站。我现在要做的是在我们登录后看到的页面上执行搜索。目前我的脚本在您登录后返回页面。它有一个带有搜索字段和按钮的表单。我还注意到它使用 __VIEWSTATE 和 __EVENTVALIDATION 作为其表单的一部分。我知道这两个字段的值并不总是相同的。所以我想知道当我执行搜索时如何从表单中检索这些值,以便我可以使用它们在我的脚本中发布表单。这是我用来登录的代码:
<?php
$post_data['ctl00$MainContent$EmailText'] = 'xxxx@xxxx.com';
$post_data['ctl00$MainContent$PasswordText'] = 'xxxx';
$post_data['ctl00$MainContent$LogInButton'] = 'Log On';
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);
$curl_connection =
curl_init('https://www.XXXX.co.uk/Login.aspx');
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl_connection, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($curl_connection);
curl_close($curl_connection);
?>