The code is as follows
$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>/",$contents,$arr);echo $arr[1];curl_close($ch);
But finally back to the login interface, small white to ask the big God answer
Reply content:
The code is as follows
$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>/",$contents,$arr);echo $arr[1];curl_close($ch);
But finally back to the login interface, small white to ask the big God answer
According to the requirements of the landlord, with my own writing of the HttpClient
class, the code is written as follows, but because there is no test account, so the test using the account and password for test
, the return of the result is landing failure, landlord only need to modify the code in the account and password, should be able to.
HTTP
The request process is Cookie
HttpClient/CURL
handled automatically by the.
The code of the landlord should be no problem, the feeling should be not submitted RadioButtonList1
and Button1
the two data.
And that __VIEWSTATE
although it seems to be fixed, but for insurance period, or should be obtained from the page after, and then submit the landing.
Attached code:
ch = curl_init (); curl_setopt ($this->ch, Curlopt_useragent, ' mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; trident/4.0; Qqdownload 685; SLCC2;. NET CLR 2.0.50727;. NET CLR 3.5.30729;. NET CLR 3.0.30729;. net4.0c;. net4.0e)//ua curl_setopt ($this->ch, Curlopt_timeout, 40); curl_setopt ($this->ch, curlopt_followlocation, TRUE); curl_setopt ($this->ch, Curlopt_autoreferer, true); curl_setopt ($this->ch, Curlopt_returntransfer, TRUE); curl_setopt ($this->ch, Curlopt_cookiejar, $cookie _jar); curl_setopt ($this->ch, Curlopt_cookiefile, $cookie _jar); } function __destruct () {curl_close ($this->ch); Final public Function setreferer ($ref = ') {if ($ref! = ') {curl_setopt ($this->ch, Curlopt_refere R, $ref); }} Final Public function Get ($url, $header =false, $nobody =false) {curl_setopt ($this->ch, Curlopt_post, FA LSE); curl_setopt ($this->ch, Curlopt_url, $url); curl_setopt ($this->ch, Curlopt_header, $header); curl_setopt ($this->ch, Curlopt_nobody, $nobody); Return curl_exec ($this->ch); Final public Function Post ($url, $data =array (), $header =false, $nobody =false) {curl_setopt ($this->ch, Curlo Pt_url, $url); curl_setopt ($this->ch, Curlopt_header, $header); curl_setopt ($this->ch, Curlopt_nobody, $nobody); curl_setopt ($this->ch, Curlopt_post, true); curl_setopt ($this->ch, Curlopt_postfields, Http_build_query ($data)); Return curl_exec ($this->ch); }}const login_url = ' http://211.64.47.129/default_ysdx.aspx '; $http = new HttpClient (Tempnam ('./temp ', ' Cookie ')); $ html = $http->get (login_url);//Request Landing page first, get __viewstatepreg_match ('/name= "__viewstate" value= "(. +?)" /', $html, $vs); if (count ($vs)!== 2) {echo ' acquires ViewState failed '; Exit ();} Construct data at login $data = array (' __viewstate ' = + $vs [1],//__viewstate ' TextBox1 ' = ' username ',//Modify the user here ' TeXtBox2 ' + ' password ',//and password ' RadioButtonList1 ' + ' student ',//and Identity type ' Button1 ' = ' login '); $html = $http->post (log In_url, $data);p reg_match ('/language=\ ' javascript\ ' >alert\ (\ ' (. +?) \ ' \);/', $html, $err);//Check for errors, display an error message if there is an error, and then exit if (count ($err) = = 2) {echo $err [1]; Exit ();} $SN = ' 123123 ';//study number $html = $http->get (' http://211.64.47.129/xs_main.aspx?xh= '. $sn);p Reg_match ('/
\s*(.*)<\/li>/', $html, $result);var_dump($result);
Https://github.com/lndj/Lcrawl/tree/dev
An elegant square educational system crawler.