querylist采集博客园博客

匿名 (未验证) 提交于 2019-12-02 23:34:01

这两天在学下采集,使用querylist,使用起来非常简单

采集博客园博客代码

<?php namespace app\index\controller; use QL\QueryList; class Index {    public function index()     {         $article=[];         for($i=1;$i<=13;$i++){         $ql = QueryList::get('https://www.cnblogs.com/jcydd/default.html?page='.$i);       // 采集文章链接    $rt= $ql->find('.postTitle a')->attrs('href');    //halt($rt);         foreach($rt as $k=>$v){                $ql2=QueryList::get($v);        $article[$i.$k]['title']=$ql2->find('#cb_post_title_url')->text();        $article[$i.$k]['date']=$ql2->find('#post-date')->text();        $article[$i.$k]['date']=strtotime($article[$i.$k]['date']);        $content=$ql2->find('#cnblogs_post_body')->html();        //获取文章图片链接        $img=$ql2->find('#topics img')->attrs('src');         //如果文章有图片,则替换图片本地地址        if(count($img)==0){           $article[$i.$k]['content']=$content;        }else{        foreach($img as $vv){            $newimgurl=getimg($vv);            $content=str_replace($vv,$newimgurl,$content);        }        $article[$i.$k]['content']=$content;        }                   }             }     dump($article);          }      }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!