奉獻(xiàn)出一個封裝的curl函數(shù) 便于調(diào)用(抓數(shù)據(jù)專用)
更新時(shí)間:2013年07月22日 23:54:30 作者:
這個函數(shù)就是封裝了curl函數(shù)的常用步驟,方便大家抓數(shù)據(jù),小偷程序也是用類似的代碼,需要的朋友可以參考下
奉獻(xiàn)出一個封裝的curl函數(shù),便于調(diào)用
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;
}
抓數(shù)據(jù)專用
復(fù)制代碼 代碼如下:
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;
}
抓數(shù)據(jù)專用
相關(guān)文章
PHP實(shí)現(xiàn)負(fù)載均衡session共享redis緩存操作示例
這篇文章主要介紹了PHP實(shí)現(xiàn)負(fù)載均衡session共享redis緩存操作,涉及php用戶登陸、session存儲、判斷等相關(guān)操作技巧,需要的朋友可以參考下2018-08-08
php foreach 參數(shù)強(qiáng)制類型轉(zhuǎn)換的問題
大家都知道foreach的參數(shù)如果不是數(shù)組類型,在運(yùn)行的時(shí)候 就會出現(xiàn)類似“Warning: Invalid argument supplied for foreach() in XXX”warning信息。2010-12-12
php下載遠(yuǎn)程文件類(支持?jǐn)帱c(diǎn)續(xù)傳)
1.功能:支持?jǐn)帱c(diǎn)續(xù)傳的下載,能計(jì)算傳輸率,能控制傳輸率2008-11-11

