站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到撫遠(yuǎn)網(wǎng)站設(shè)計(jì)與撫遠(yuǎn)網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、國(guó)際域名空間、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋撫遠(yuǎn)地區(qū)。
/*網(wǎng)頁(yè)爬蟲(chóng)*/
#最簡(jiǎn)單的使用,屬性都采用默認(rèn)值
/*
$curl=curl_init('http://www.baidu.com');
$output=curl_exec($curl);
curl_close($curl);
echo $output;
*/
#稍微復(fù)雜一點(diǎn)的,對(duì)頁(yè)面進(jìn)行操作
/*
$curl=curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.baidu.com');//可以動(dòng)態(tài)改變網(wǎng)址
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//不直接打印在瀏覽器上
$output=curl_exec($curl);//執(zhí)行
curl_close($curl);//關(guān)閉
echo str_replace('百度', '虎哥', $output);
*/
#更復(fù)雜一點(diǎn)的,模擬POST請(qǐng)求
/*
$data='theCityName=北京';
$curl=curl_init();
curl_setopt($curl, CURLOPT_URL,'http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName');
curl_setopt($curl,CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_POST, 1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
curl_setopt($curl,CURLOPT_HTTPHEADER,array('application/x-www-form-rulencode;charset=utf-8','Content-length'.strlen($data)));
$output=curl_exec($curl);
if(!curl_errno($curl)){
//$info=curl_getinfo($curl);
//print_r($info);
header('Content-type:text/html;charset=utf-8;');
echo $output;
}else{
echo 'Curl Error:'.curl_error($curl);
}
curl_close($curl);
*/
#抓取需要登錄的頁(yè)面
/*
$data='username=2232839753@qq.com&password=19900417&remember=1';
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,'http://www.imooc.com/user/login');
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);//執(zhí)行之后不直接打印出來(lái)
//Cookie相關(guān)設(shè)置,這部分設(shè)置需要在所有回話開(kāi)始之前設(shè)置
date_default_timezone_set('PRC');//使用cookie時(shí)必須設(shè)置時(shí)區(qū)
curl_setopt($curl,CURLOPT_COOKIESESSION, true);
curl_setopt($curl,CURLOPT_COOKIEFILE,'cookiefile');
curl_setopt($curl,CURLOPT_COOKIEJAR,'cookiefile');
curl_setopt($curl,CURLOPT_COOKIE, session_name().'='.session_id());
curl_setopt($curl,CURLOPT_HEADER,0);//禁止輸出頭信息
curl_setopt($curl,CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl,CURLOPT_POST, 1);
curl_setopt($curl,CURLOPT_POSTFIELDS, $data);
curl_setopt($curl,CURLOPT_HTTPHEADER,array('application/x-www-form-rulencode;charset=utf-8','Content-length:'.strlen($data)));
curl_exec($curl);//執(zhí)行
curl_setopt($curl,CURLOPT_URL,'http://www.imooc.com/space/index');
curl_setopt($curl,CURLOPT_POST,0);//下載頁(yè)面不是post請(qǐng)求,故置0
curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-type:text/xml'));
$output=curl_exec($curl);
echo $output;
*/
#從ftp curl_setopt($curl,CURLOPT_HEADER,0);//禁止輸出頭信息,調(diào)試時(shí),可以輸出 curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl,CURLOPT_TIMEOUT,300);//設(shè)置超時(shí)時(shí)間,單位秒 curl_setopt($curl,CURLOPT_USERPWD,"admin:123");//ftp用戶名,密碼 $outfile=fopen('mytest.txt', 'wb');//保存到本地的文件名 curl_setopt($curl,CURLOPT_FILE,$outfile); $output=curl_exec($curl); fclose($outfile); if(!curl_errno($curl)){ //$info=curl_getinfo($curl); //print_r($info); echo "RETURN:".$output; }else{ echo 'Curl error:'.curl_error($curl); } curl_close($curl); */ #ftp文件上傳 /* $curl=curl_init(); $uploadfile='demo1.php'; $fp=fopen($uploadfile,'r'); curl_setopt($curl, CURLOPT_URL, 'ftp://10.14.12.22:21/uploadfile.php'); curl_setopt($curl, CURLOPT_HEADER,0); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); curl_setopt($curl, CURLOPT_TIMEOUT,300); curl_setopt($curl,CURLOPT_USERPWD,'admin:123'); curl_setopt($curl,CURLOPT_UPLOAD,1); curl_setopt($curl, CURLOPT_INFILE, $fp); curl_setopt($curl,CURLOPT_INFILESIZE,filesize($uploadfile)); $output=curl_exec($curl); fclose($fp); if(!curl_errno($curl)){ echo 'uploadfile successfully'; }else{ echo 'uploadfile error:'.curl_error($curl); } curl_close($curl); */ #curl訪問(wèn)https上的資源 /* $curl=curl_init(); curl_setopt($curl,CURLOPT_URL,'https://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.js'); curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); date_default_timezone_set('PRC'); curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);//終止從服務(wù)端進(jìn)行驗(yàn)證 $output=curl_exec($curl); curl_close($curl); echo $output; */ //php官方文檔網(wǎng)址:http://php.net/manual/zh/book.curl.php ?>
網(wǎng)站名稱:php網(wǎng)頁(yè)爬蟲(chóng)
網(wǎng)頁(yè)網(wǎng)址:http://weahome.cn/article/ijchgh.html