首先,我们还是接上一篇抓取数据博文为例:/qq_39188306/article/details/88262095,虽然这篇博文能够正常抓取数据,但是不能够实现实时抓取,也就是要手动刷新才能执行任务。那么接下来我们配置一下:
一、先谈谈windows下执行:
1、新建一个.bat文件:
内容如下:"D:\phpStudy\PHPTutorial\php\php-7.0.12-nts\php.exe" -f "D:\phpStudy\PHPTutorial\WWW\andy\public\index.php" "index/index/index"
如果已经配置过(PHP)环境变量 :php-f "D:\phpStudy\PHPTutorial\WWW\andy\public\index.php" "index/index/index"
如果你的是多级控制器:"D:\phpStudy\PHPTutorial\WWW\andy\public\index.php" "index/arm.index/index"
2、打开 任务计划程序
开始-控制面板-管理工具-任务计划程序
添加任务配置如下
如果你配置后,仍然不能运行:请使用cmd命令执行看看报错:
执行命令:"D:\phpStudy\PHPTutorial\php\php-7.0.12-nts\php.exe" -f "D:\phpStudy\PHPTutorial\WWW\andy\public\index.php" "index/index/index"
配置过(PHP)环境变量,执行命令:php -f "D:\phpStudy\PHPTutorial\WWW\andy\public\index.php" "index/index/index"
我这个是能够正常运行的!
二、我们在Nginx宝塔面板上执行计划任务:
路径写法:php /www/wwwroot/ad-test.lsing.top/public/index.php index/happiness.index/collection
看看日志,是否成功: