cURL - 自定义get方法抓取网页
发布时间:2020-12-14 02:05:40 所属栏目:Linux 来源:网络整理
导读:? php $content = get(‘http://www.xmtnews.com/events‘ ); preg_match (‘/section class="ov"(.*?)div class="hr-10"/div/mis‘, $content , $match ); // 将正则匹配到的内容赋值给$area $area = $match [1 ]; preg_match_all (‘/h3a href="(.*?)" ti
<?php $content = get(‘http://www.xmtnews.com/events‘); preg_match(‘/<section class="ov">(.*?)<div class="hr-10"></div>/mis‘,$content,$match); //将正则匹配到的内容赋值给$area $area = $match[1]; preg_match_all(‘/<h3><a href="(.*?)" title=".*?" class="headers" target="_blank">(.*?)</a></h3>/‘,$area,$find); var_dump($find);die; function get($url) { //初使化curl $ch = curl_init(); //请求的url,由形参传入 curl_setopt($ch,CURLOPT_URL,$url); //将得到的数据返回 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //不处理头信息 curl_setopt($ch,CURLOPT_HEADER,0); //连接超过10秒超时 curl_setopt($ch,CURLOPT_TIMEOUT,10); //执行curl $output = curl_exec($ch); //关闭资源 curl_close($ch); //返回内容 return $output; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |