奉獻出一個封裝的curl函數 便于調用(抓數據專用)
更新時間:2013年07月22日 23:54:30 作者:
這個函數就是封裝了curl函數的常用步驟,方便大家抓數據,小偷程序也是用類似的代碼,需要的朋友可以參考下
奉獻出一個封裝的curl函數,便于調用
function curl($url, $ifpost = 0, $datafields = '', $cookiefile = '', $v = false) {
$header = array("Connection: Keep-Alive","Accept: text/html, application/xhtml+xml, */*", "Pragma: no-cache", "Accept-Language: zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3","User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $v);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$ifpost && curl_setopt($ch, CURLOPT_POST, $ifpost);
$ifpost && curl_setopt($ch, CURLOPT_POSTFIELDS, $datafields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
$cookiefile && curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
$cookiefile && curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
抓數據專用
復制代碼 代碼如下:
function curl($url, $ifpost = 0, $datafields = '', $cookiefile = '', $v = false) {
$header = array("Connection: Keep-Alive","Accept: text/html, application/xhtml+xml, */*", "Pragma: no-cache", "Accept-Language: zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3","User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $v);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$ifpost && curl_setopt($ch, CURLOPT_POST, $ifpost);
$ifpost && curl_setopt($ch, CURLOPT_POSTFIELDS, $datafields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
$cookiefile && curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
$cookiefile && curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
抓數據專用
相關文章
php中array_column函數簡單實現(xiàn)方法
這篇文章主要介紹了php中array_column函數簡單實現(xiàn)方法,結合實例形式簡單分析了array_column函數的功能,并針對低版本的情況給出了array_column函數的實現(xiàn)代碼,需要的朋友可以參考下2016-07-07PHP 循環(huán)刪除無限分類子節(jié)點的實現(xiàn)代碼
本篇文章是對PHP中循環(huán)刪除無限分類子節(jié)點的代碼進行了詳細的分析介紹,需要的朋友參考下2013-06-06Php output buffering緩存及程序緩存深入解析
在php中有時為了控制程序的輸出顯示順序,提供了output buffering緩存(php自身緩存機制)。若Ob緩存開啟,需要輸出的就先存在ob緩存里,再到程序緩存里。若沒有開啟,則直接進入程序緩存,程序執(zhí)行完畢,按照順序從程序緩存里輸出2013-07-07