天天看點

curl實作模拟登陸

<?php

$url = "http://202.119.81.118:7777/pls/wwwxk/xk.login";//output.php為接受檔案,内容為print_r($_POST)

$cookie_file=tempnam('./temp','cookie');

$post_fields='stuid=912101500310&pwd=123321';

$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_URL, $url);//要通路的位址

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//執行結果是否被傳回,0是傳回,1是不傳回

curl_setopt($ch, CURLOPT_POST, 1);// 發送一個正常的POST請求

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);//POST送出的資料包

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);

curl_setopt($ch, CURLOPT_TIMEOUT, 30);//設定逾時

$output = curl_exec($ch);//執行并擷取資料

curl_close($ch);

// var_dump($output);

$url='http://202.119.81.118:7777/pls/wwwxk/xk.CourseView';

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);

$contents = curl_exec($ch);

curl_close($ch);

?>

我真的是醉了,寫出這個抓到教務處的課表真的是好激動,結果那個"占座寶"直接給我來了一句,考驗的不是你抓取頁面的能力,而是你過濾字元串的能力,我真的是XXX!!!   繼續努力吧~~TT