我有一個運行的Python Scrapy抓取的多個實例的腳本,爬行是INT /root/crawler/batchscript.py
無法更改目錄使用bash腳本 - cron的
和/root/crawler/
我有scrapy履帶。
爬行者工作得很好。
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腳本太 創建bash腳本稱爲batchinit.sh
#!/bin/bash
alias batchscript="cd /root/crawler/"
python batchscript.py
和行爲是相同:(
當我運行
batchinit.sh
內/root/crawler/
目錄刮板 運行好。B當我從這個目錄之外運行它使用
bash /root/crawler/batchinit.sh
然後它不按預期運行, (設置不正確導入),get_project_settings()
是 空。
爲什麼我這麼做?什麼是最終目標?
我想爲這個腳本創建一個cronjob。我試圖使用上面提到的命令安排cronjob,但是我有上面提到的問題。
你想通過在shell腳本中定義別名來做什麼?爲什麼不把cd/root/crawler /放在該行而不是將其別名化爲批處理腳本? –
scrapy和amazon_crawler模塊在哪裏?他們是在一個虛擬的環境? – lucasnadalutti
這可能有所幫助:http://stackoverflow.com/a/22466264/2874789 –