采集网站 相关文件--ArticleJob.php [ 1.0 版本 ] [ 1.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;
}
}
}
}
specialnot
注册时间:2015-08-06
最后登录:2019-08-16
在线时长:27小时54分
最后登录:2019-08-16
在线时长:27小时54分
- 粉丝43
- 金钱1175
- 威望200
- 积分3445
共 0 条评论