自定製命令
在spiders同級建立任意目錄,如:commands
在其中建立 crawlall.py 檔案 (此處檔名就是自定義的命令)
from scrapy.commands import scrapycommand
from scrapy.utils.project import get_project_settings
class command(scrapycommand):
requires_project = true
def syntax(self):
return '[options]'
def short_desc(self):
return 'runs all of the spiders'
def run(self, args, opts):
spider_list = self.crawler_process.spiders.list()
for name in spider_list:
self.crawler_process.crawl(name, **opts.__dict__)
self.crawler_process.start()
在settings.py 中新增配置 commands_module = '專案名稱.目錄名稱'
在專案目錄執行命令:scrapy crawlall
自定製模版
sublime 有乙個很簡單的特點,就是所有使用者自定製的內容都會放在乙個資料夾中。不同的作業系統肯定是不同的,google 一下就知道了,不過 mac 系統下是 寫到這裡的資料是不會被自動公升級而被覆蓋的。可以到 menu sublime text preferences browse packa...
Scrapy設定之自定義命令
commands module允許開發者自定義命令,假設工程名字為properties,在工程的根目錄有乙個hi.py檔案內容如下 from scrapy.commands import scrapycommand class command scrapycommand default settin...
scrapy 基礎元件專題(六) 自定義命令
寫好自己的爬蟲專案之後,可以自己定製爬蟲執行的命令。一 單爬蟲 在專案的根目錄下新建乙個py檔案,如命名為start.py,寫入如下 from scrapy.cmdline import execute if name main execute scrapy crawl chouti nolog 執...