我有一个运行多个Python爬虫实例的脚本,Crawler是int /root/crawler/batchscript.py
在/root/crawler/,我有一个刮擦的爬虫。
爬虫工作得很好。
batchscript.py看起来像这样,(只发布相关代码)
from scrapy.settings import Settings
from scrapy.utils.project import get_project_settings
from amazon_crawler.spiders.amazon_scraper import MySpider
process = CrawlerProcess(get_project_settings())当我在batchscrip.py目录下运行/root/crawler/时,刮板就能正常运行。
但是,当我使用python /root/crawler/batchscript.py从这个目录外部运行它时,它不会按预期运行(设置没有正确导入),get_project_settings()是空的。
我也尝试过创建一个BASH脚本--我创建了一个名为batchinit.sh的bash脚本
#!/bin/bash
alias batchscript="cd /root/crawler/"
python batchscript.py而行为是一样的:
当我在
batchinit.sh目录下运行/root/crawler/时,刮板就能正常运行。 但是,当我使用bash /root/crawler/batchinit.sh从这个目录外部运行它时,它不会按预期运行(设置没有正确导入),get_project_settings()是空的。
我为什么要这么做?最终目标是什么?
我想为这个脚本创建一个cronjob。我试着使用上面提到的命令来调度cron作业,但正如上面提到的,我有一些问题。
发布于 2016-11-17 18:42:11
使用bash,您总是可以:
cd /root/crawler && python batchscript.py使用在cron作业中引用的程序/可执行文件的绝对路径始终是一个好策略。
https://stackoverflow.com/questions/40662620
复制相似问题