用cURL登陸慕課網(wǎng)并下載個(gè)人空間頁(yè)面 代碼,加上自己的賬號(hào)密碼
<?php /** ?*?慕課網(wǎng)視頻教學(xué) ?*?代碼實(shí)例-PHP-cURL實(shí)戰(zhàn) ?*?實(shí)例描述:登錄慕課網(wǎng)并下載個(gè)人空間頁(yè)面 ?*?自定義實(shí)現(xiàn)頁(yè)面鏈接跳轉(zhuǎn)抓取 ?* ?*/ $data='username=你的賬號(hào)&password=你的密碼&remember=1'; $curlobj?=?curl_init();??????????//?初始化 curl_setopt($curlobj,?CURLOPT_URL,?"http://idcbgp.cn/user/login");????//?設(shè)置訪(fǎng)問(wèn)網(wǎng)頁(yè)的URL curl_setopt($curlobj,?CURLOPT_RETURNTRANSFER,?true);?????????//?執(zhí)行之后不直接打印出來(lái) //?Cookie相關(guān)設(shè)置,這部分設(shè)置需要在所有會(huì)話(huà)開(kāi)始之前設(shè)置 date_default_timezone_set('PRC');?//?使用Cookie時(shí),必須先設(shè)置時(shí)區(qū) curl_setopt($curlobj,?CURLOPT_COOKIESESSION,?TRUE); curl_setopt($curlobj,?CURLOPT_COOKIEFILE,?"mycookie"); curl_setopt($curlobj,?CURLOPT_COOKIEJAR,?"mycookie"); curl_setopt($curlobj,CURLOPT_COOKIE,session_name().'='.session_id()); curl_setopt($curlobj,CURLOPT_HEADER,0); //?注釋掉這行,因?yàn)檫@個(gè)設(shè)置必須關(guān)閉安全模式?以及關(guān)閉open_basedir,對(duì)服務(wù)器安全不利 curl_setopt($curlobj,?CURLOPT_FOLLOWLOCATION,?1); curl_setopt($curlobj,?CURLOPT_POST,?1); curl_setopt($curlobj,?CURLOPT_POSTFIELDS,?$data); curl_setopt($curlobj,?CURLOPT_HTTPHEADER,?array("application/x-www-form-urlencoded;?charset=utf-8", ???"Content-length:?".strlen($data) )); curl_exec($curlobj);???//?執(zhí)行 curl_setopt($curlobj,?CURLOPT_URL,?"http://idcbgp.cn/space/index"); curl_setopt($curlobj,?CURLOPT_POST,?0); curl_setopt($curlobj,?CURLOPT_HTTPHEADER,?array("Content-type:?text/xml" )); //$output=curl_redir_exec($curlobj);???//?執(zhí)行 $output?=?curl_exec($curlobj); curl_close($curlobj);????????//?關(guān)閉cURL echo?$output; ?>
一開(kāi)始不管用,因?yàn)闆](méi)加
curl_setopt($curlobj,?CURLOPT_COOKIEFILE,?"mycookie"); curl_setopt($curlobj,?CURLOPT_COOKIEJAR,?"mycookie"); curl_setopt($curlobj,CURLOPT_COOKIE,session_name().'='.session_id());
分享一下