php 模仿百度蜘蛛采取网页信息

来源:互联网 发布:苹果预约软件 编辑:程序博客网 时间:2024/05/18 14:44
function vspider_get($url){

        $ch2 = curl_init();
        $user_agent = "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)";//这里模拟的是百度蜘蛛
        curl_setopt($ch2, CURLOPT_URL, $url);
        curl_setopt($ch2, CURLOPT_HEADER, false);
        curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch2, CURLOPT_REFERER, 'www.baidu.com');//1这里写一个来源地址,可以写要抓的页面的首页
        curl_setopt($ch2, CURLOPT_USERAGENT, $user_agent);
        $temp=curl_exec($ch2);
        return $temp;
    }

    $url="www.baidu.com";//2要抓取的地址

    $contents=vspider_get($url);

    var_dump($contents);

0 0
原创粉丝点击