Crawl 相关方法

来源:互联网 发布:显卡功耗测试软件 编辑:程序博客网 时间:2024/06/05 10:41
<?phpclass Crawl{public static $lastErrorNo;public static $lastError;public static function getCurl($url, $data=array(),$isPost = true, $header = array()){$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);$header && curl_setopt($curl, CURLOPT_HTTPHEADER, $header);curl_setopt($curl, CURLOPT_POST, false);if($isPost){curl_setopt($curl, CURLOPT_POST, true);curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));}$response = curl_exec($curl);if(self::$lastErrorNo = curl_errno($curl)){self::$lastError   = curl_error($curl);}curl_close($curl);return $response ;}public static function getStream($url,$data=array(),$type="POST",$timeout=60){$data = http_build_query($data);$options = array('http' => array('method' => $type,'header' => 'Content-type:application/x-www-form-urlencoded','content' => $data,'timeout' => $timeout,// 超时时间(单位:s)),);$context = stream_context_create($options,array());$result = file_get_contents($url, false, $context);return $result;}}

0 0
原创粉丝点击