<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                > 安裝 QueryList `composer require jaeger/querylist` ``` ~~~ <?php namespace app\common\service; use QL\QueryList; use think\Db; use think\Exception; class PaContent { /** * @return array * 獲取數據 */ public static function save_data(){ $page=self::get_page();//獲取分頁 if ($page >27){ return ['code'=>0,'msg'=>'分頁數據最大27頁']; } ini_set('max_execution_time', 600);//秒為單位,自己根據需要定義 ini_set('memory_limit', '256M');//內存 $url = 'https://www.cbf.com.br/pelo-mundo/noticias/index?page='.$page; // 采集規則 $rules = [ // 文章標題 'title' => ['div>h2>a','text'], 'img' => ['.pull-left>a>img','src'], 'link' => ['div>h2>a','href'], ]; // 切片選擇器 $range = '.news'; $data=QueryList::get($url)->rules($rules)->query()->range($range)->queryData();//多個數組 if (empty($data)){ return ['code'=>0,'msg'=>'未爬取到數據']; } $arr=[]; foreach ($data as $k=>$v){ $content=self::get_content_detail($v['link']); if ($content['code']==0){ continue ; } $arr[$k]['content']=$content['data']; $arr[$k]['title']=$v['title']; $img=self::getImage($v['img']); $arr[$k]['image']=$img['save_path']; //$arr[$k]['link']='https://www.cbf.com.br'.$v['link']; $arr[$k]['createtime']=time()-mt_rand(50,900); } return self::save_data_to_database($arr,$page); } protected static function set_page($page){ @file_put_contents('num.txt',$page+1); return true; } protected static function get_page(){ $page=@file_get_contents('num.txt'); return intval($page); } /** * @param $arr * @param $page * @return array * 保存數據 */ protected static function save_data_to_database($arr,$page){ if (empty($arr)) return ['code'=>0,'msg'=>'無數據可保存']; $result=Db::name('content')->insertAll($arr); if ($result){ self::set_page($page); //更新下次分頁次數 return ['code'=>1,'msg'=>'數據保存成功條數:'.$result]; } return ['code'=>0,'msg'=>'數據保存失敗']; } /** * @param $url * @return string|string[]|null * 獲取內容詳細html */ protected static function get_content_detail($url){ $url='https://www.cbf.com.br'.$url; try { $ql = QueryList::get($url, null, [ 'headers' => [ 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36', 'Accept-Encoding' => 'gzip, deflate, br', ] ]); }catch (Exception $exception){ return ['code'=>0,'msg'=>'獲取詳細內容異常']; } //獲取內容html $da=$ql->find(".article-inner-content")->html(); //去掉圖片 $content= preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i','',$da); return ['code'=>1,'msg'=>'ok','data'=>$content]; } /** * @param $url * @param string $save_dir * @param int $type * @return array * 遠程圖片本地化 */ public static function getImage($url,$save_dir='./content_img/',$type=0){ if(trim($url)==''){ return array('file_name'=>'','save_path'=>'','error'=>1); } $ext=strrchr($url,'.'); if($ext!='.gif'&&$ext!='.jpg'&&$ext!='.png'&&$ext!='.jpeg'){ return array('file_name'=>'','save_path'=>'','error'=>2); } $filename=time().$ext; //創建保存目錄 if(!file_exists($save_dir)&&!mkdir($save_dir,0777,true)){ return array('file_name'=>'','save_path'=>'','error'=>3); } //獲取遠程文件所采用的方法 ob_start(); readfile($url); $img=ob_get_contents(); ob_end_clean(); //$size=strlen($img); //文件大小 $fp2=@fopen($save_dir.$filename,'a'); fwrite($fp2,$img); fclose($fp2); unset($img,$url); return array('file_name'=>$filename,'save_path'=>'/content_img/'.$filename,'error'=>0); } } ~~~ ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看