specialnot 2015-11-16 15:23:52 3924次浏览 0条评论 0 0 0

YII2网站采集
(1)QueueController.php
(2)ArticleController.php
(3)ArticleJob.php
(4)ArticleSpider.php
(5)YiichinaSpider.php

<?php
    namespace console\models;

    use yii\base\Exception;

    class ArticleJob{
        public function perform()
        {
            //获取队列内容属性
            $args=$this->args;
            $category= $args['category'];
            $url= $args['url'];
            $baseClassName= $args['className'];
            $publishTime = $args['publishTime'];
            $className = '\console\models\\'.ucfirst(strtolower($baseClassName)).'Spider';
            if(!class_exists($className)){
                throw new Exception($baseClassName.' Class does not exist');
            }
            $class = new $className;
            $res = $class->getContent(trim($url),$category);
            $res = json_decode($res,true);
            if($res){
                $title = $res['title'];
                $content = $res['content'];
                $time = $res['time'];
                $time = $publishTime?:$time;
               try{
                   $result = $class->insert($title,$content,$time,$category);
                   $class->addLog($url,$category,$result,$title);
               }catch(\Exception $e){
                   echo $e->getMessage().PHP_EOL;
               }
            }

        }
    }
    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册