代码如下:
<?php
function curl_request($url,$post=””,$cookie=””, $returnCookie=0){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, “Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)”);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_REFERER, “http://XXX”);
if($post) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
}
if($cookie) {
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
}
curl_setopt($curl, CURLOPT_HEADER, $returnCookie);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
if (curl_errno($curl)) {
return curl_error($curl);
}
curl_close($curl);
if($returnCookie){
list($header, $body) = explode(“\r\n\r\n”, $data, 2);
preg_match_all(“/Set\-Cookie:([^;]*);/”, $header, $matches);
$info[“cookie”] = substr($matches[1][0], 1);
$info[“content”] = $body;
return $info;
}else{
return $data;
}
}
function getView(){
$res;
$url = “http://210.34.213.87/default2.aspx”;
$result = curl_request($url);
$pattern = “/<input type=”hidden” name=”__VIEWSTATE” value=”(.*?)” \/>/is”;
preg_match_all($pattern, $result, $matches);
$res[0] = $matches[1][0];
$pattern = “/<input type=”hidden” name=”__VIEWSTATEGENERATOR” value=”(.*?)” \/>/is”;
preg_match_all($pattern, $result, $matches);
$res[1] = $matches[1][0];
return $res[0];
}
function login($VS){
$url = “http://210.34.213.87/default2.aspx”;
$post[“__VIEWSTATE”] = $VS;
$post[“txtUserName”] = “1102062104”;
$post[“TextBox2”] = “zhy12345”;
$post[“txtSecretCode”] = “”;
$post[“RadioButtonList1”] = iconv(“utf-8”, “gb2312”, “学生”);
$post[“Button1”] = iconv(“utf-8”, “gb2312”, “登录”);
$post[“lbLanguage”] = “”;
$post[“hidPdrs”] = “”;
$post[“hidsc”] = “”;
$result = curl_request($url,$post,””, 1);
//print_r($result);
return $result;
}
$a = getView();
$L = login($a);
$cookie = $L[cookie];
//登陆主页
$url = “http://210.34.213.87/xs_main.aspx?xh=1102062104″;
$result = curl_request($url,””,$cookie); //我们保存的cookies
//print_r($result);
//获取课表页面
$url = “http://210.34.213.87/xskbcx.aspx?xh=1102062104″;
$result1 = curl_request($url,””,$cookie);
print_r($result1);
?>
<?php
function curl_request($url,$post=””,$cookie=””, $returnCookie=0){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, “Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)”);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_REFERER, “http://XXX”);
if($post) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
}
if($cookie) {
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
}
curl_setopt($curl, CURLOPT_HEADER, $returnCookie);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
if (curl_errno($curl)) {
return curl_error($curl);
}
curl_close($curl);
if($returnCookie){
list($header, $body) = explode(“\r\n\r\n”, $data, 2);
preg_match_all(“/Set\-Cookie:([^;]*);/”, $header, $matches);
$info[“cookie”] = substr($matches[1][0], 1);
$info[“content”] = $body;
return $info;
}else{
return $data;
}
}
function getView(){
$res;
$url = “http://210.34.213.87/default2.aspx”;
$result = curl_request($url);
$pattern = “/<input type=”hidden” name=”__VIEWSTATE” value=”(.*?)” \/>/is”;
preg_match_all($pattern, $result, $matches);
$res[0] = $matches[1][0];
$pattern = “/<input type=”hidden” name=”__VIEWSTATEGENERATOR” value=”(.*?)” \/>/is”;
preg_match_all($pattern, $result, $matches);
$res[1] = $matches[1][0];
return $res[0];
}
function login($VS){
$url = “http://210.34.213.87/default2.aspx”;
$post[“__VIEWSTATE”] = $VS;
$post[“txtUserName”] = “1102062104”;
$post[“TextBox2”] = “zhy12345”;
$post[“txtSecretCode”] = “”;
$post[“RadioButtonList1”] = iconv(“utf-8”, “gb2312”, “学生”);
$post[“Button1”] = iconv(“utf-8”, “gb2312”, “登录”);
$post[“lbLanguage”] = “”;
$post[“hidPdrs”] = “”;
$post[“hidsc”] = “”;
$result = curl_request($url,$post,””, 1);
//print_r($result);
return $result;
}
$a = getView();
$L = login($a);
$cookie = $L[cookie];
//登陆主页
$url = “http://210.34.213.87/xs_main.aspx?xh=1102062104″;
$result = curl_request($url,””,$cookie); //我们保存的cookies
//print_r($result);
//获取课表页面
$url = “http://210.34.213.87/xskbcx.aspx?xh=1102062104″;
$result1 = curl_request($url,””,$cookie);
print_r($result1);
?>
解决方案
1
有验证码的嘛
2
本人记得方正系统中海油name=”status”的表单,你要把他的值也回传
17
https://github.com/Chrisdowson/gxlm这是本人本人写了10几所大学的,用PHP写的,本人把他开源了。虽然不完整,希望能帮到你