您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php 利用curl模仿用户采集远程网站内容

2024/4/10 8:59:01发布15次查看
本程序是先利用判断服务器是否是支持curl_init如果是就模仿用户读取远程数据,并且 进行解析正则过滤不要的信息,否则就用file采集远程数据,如果服务器还不支持file就提示无法采集想要的内容
代码如下 复制代码
$timestamp = time();
function open($file,$type=''){
        global $fromurl,$referer;
        $cachename=$file;
                if($type){
                        $file='/'.$type.'/'.$file;
                }else{
                        $file=$file;
                }
                        if($open=file($file)){
                                        $count=count($open);
                                        for($i=0;$i                                                $theget.=$open[$i];
                                        }
                                }else{
                                        die('无法连接源站网络,请刷新');
                                }
        return $theget;
}
function cut($file,$from,$end){
        $message=explode($from,$file);
        $message=explode($end,$message[1]);
return        $message[0];
}
function curl($openurl)
{
 global $isfun;
 if($isfun==curl){
 $ch = curl_init($openurl);
 curl_setopt($ch, curlopt_followlocation, 1);
 curl_setopt($ch, curlopt_returntransfer, 1);
 $file = curl_exec($ch);
 curl_close($ch);
 }
 elseif($isfun==fopen){
  $file=open($openurl);
 }
 else{ echo ;}
 return $file;
}
//使用方法
 代码如下 复制代码
$url = 'http://www.111cn.net';
$content = open($url,0);
/*
下面的函数用来判断函数是否可用
*/
 代码如下 复制代码
function isfun($funname)
 {
        return (false !== function_exists($funname))?yes:no;
 }
?>
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product