1.解析各个爬虫执行的文件
processSpider.py
import os
import re
class processAllSpider(object):
@staticmethod
def processSpider():
"""
取当前路径下的所有文件和文件夹
:return:
"""
for root, dirs, files in os.walk(os.getcwd()):
for file in files:
result = re.search(r"main_[a-z_]*.py", file)
if result:
print("当前运行",result.group())
os.chdir(root)
os.system('python3 ' + result.group())
return "spiders run completed."
processAllSpider.processSpider()
2.processSpider.sh
#!/bin/sh echo "start staffing spider" base_PATH=$(cd `dirname $0`;pwd) echo "base_path is $base_PATH" cd $base_PATH && python3 processSpider.py
processSpider.py文件及processSpider.sh文件位于同一目录下
3.在linux中使用crontab设置定时
sudo vim /etc/crontab
然后在文件中加入要运行的processSpider.sh脚本
例:
每天晚上10点40分运行processSpider.sh文件
40 22 * * * User sh pocessSpider.sh文件所在的绝对路径



