CURL 请求数据

xiaoxiao2021-02-28  112

public static function curlPage($paramArr){ if (is_array($paramArr)) { $options = array( 'url' => false, #要请求的URL数组 'timeout' => 2, #超时时间 s ); $options = array_merge($options, $paramArr); extract($options); } $timeout = (int)$timeout; if(0 == $timeout || empty($url))return false; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); if(defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){ # 避免首先解析ipv6 curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); } $data = curl_exec($ch); curl_close($ch); return $data; }

CURL 不是所有网站内容都能抓取的到,这个时候需要用到模拟浏览器访问了.

转载请注明原文地址: https://www.6miu.com/read-59226.html

最新回复(0)