python.scrapy 之crawlall命令执行所有的spiders
2014-11-25 17:20
417 查看
#!/usr/local/bin/python2.7 # -*- coding: utf-8 -*- # encoding=UTF-8 ''' Created on 2014年11月5日 @author: songs ''' from scrapy.command import ScrapyCommand from scrapy.utils.project import get_project_settings from scrapy.crawler import Crawler class Command(ScrapyCommand): requires_project = True def syntax(self): return '[options]' def short_desc(self): return 'Runs all of the spiders' def add_options(self, parser): ScrapyCommand.add_options(self, parser) def process_options(self, args, opts): ScrapyCommand.process_options(self, args, opts) def run(self, args, opts): settings = get_project_settings() crawler = self.crawler_process.create_crawler() for spider_name in crawler.spiders.list(): crawler = Crawler(settings) crawler.configure() spider = crawler.spiders.create(spider_name) crawler.crawl(spider) crawler.start() # spider = crawler.spiders.create(spider_name, **opts.spargs) # crawler.crawl(spider) self.crawler_process.start()
/projectname/projectname/commands/:
__init__.py
crawlall.py
注:以上目录__init__.py必须存在
相关文章推荐
- Scrapy执行crawl命令报错:ModuleNotFoundError: No module named 'win32api'
- Python.错误解决:scrapy 没有crawl 命令
- python 执行系统命令比较
- python 执行外部命令
- python 执行系统命令
- ssh批量登录并执行命令的python实现代码
- Python执行系统命令的方法 os.system(),os.popen(),commands
- 记录MySQL下所执行的所有命令
- python 执行系统命令比较[zz]
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- [转]Python执行系统命令的方法 os.system(),os.popen(),commands
- yum命令执行报错(python升级导致)
- python 利用pexpect进行多机远程命令执行
- python执行第三方命令
- python 执行外部命令
- python类库32[执行外部命令]
- Python中执行shell命令的实例
- python 执行命令 获取返回值 和 print内容 用module commands
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- Python执行系统命令的方法 os.system(),os.popen(),commands