模拟登录 - php CURL模拟登陆正方教务系统
阿神
阿神 2017-04-10 17:33:45
0
1
596

代码如下

$cookie_file    =    tempnam('./temp','cookie');
$login_url        =    'http://211.64.47.129/default_ysdx.aspx';
$post_fields    =    '__VIEWSTATE=dDw1MjQ2ODMxNzY7Oz7xlHJHd0KfeVRA2p7BXNto118wbQ==&TextBox1=学号&TextBox2=密码';

$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);

curl_exec($ch);
curl_close($ch);


$url='http://211.64.47.129/xs_main.aspx?xh=学号';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

$contents = curl_exec($ch);
preg_match("/<li>  (.*)<\/li>/",$contents,$arr);
echo $arr[1];
curl_close($ch);

但是最后却回到了登录的界面,小白求大神解答

阿神
阿神

闭关修行中......

reply all(1)
洪涛

https://github.com/lndj/Lcrawl/tree/dev

一只优雅的正方教务系统爬虫。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template