采集指定页面的标题,关键字

public function classdate(){
       
        $find = \think\Db::table('classa')->field('id,folder,ClassBasicInfo')->select();
        $arr = [];
        foreach ($find as $key => $value) {
            $arr[$key]['url'] = 'http://www.xxx.com/' . $value['folder'];
            $arr[$key]['id'] =$value['id'];
        }
        return $arr;
    } 

public function curl(){
       
        set_time_limit(0);
        $ch = array();
        $res = array();
        $conn = array();

        $html=[];
        $urls =$this->classdate();
        foreach ($urls as $key => $url) {
            $ch = curl_init($url['url']);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $result = curl_exec($ch);
            curl_close($ch);
            $html[$key]['id']= $url['id'];
            $html[$key]['title'] = preg_match('!<title>(.*?)</title>!i', $result, $matches) ? $matches[1] : '';
            $html[$key]['keywords'] = preg_match('/<META\s+name="keywords"\s+content="([\w\W]*?)"/si', $result, $matches) ? $matches[1] : '';
            $html[$key]['desc'] = preg_match('/<META\s+name="description"\s+content="([\w\W]*?)"/si', $result, $matches) ? $matches[1] : '';
            $update = \think\Db::table('classa')->where('id', $url['id'])->update([
                'title'=>$html[$key]['title'],
                'keywords' =>$html[$key]['keywords'],
                'desc'=>$html[$key]['desc'],
            ]);
        }
        dump($html);
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值