萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> 編程語言綜合 >> 奉獻出一個封裝的curl函數 便於調用(抓數據專用)

奉獻出一個封裝的curl函數 便於調用(抓數據專用)

這個函數就是封裝了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;
}



抓數據專用

copyright © 萬盛學電腦網 all rights reserved