关于SCRAPY运行多个SPIDER的问题
来源:互联网 发布:软件架构 书籍 编辑:程序博客网 时间:2024/05/16 15:01
最近在写爬取新闻的爬虫,但是发现scrapy不支持一次同时启动多个spider,到网上查找了各种资料,可能是版本的问题均不得法。
有说用scrapyd来调度scrapy的,也搭建试用了一下scrapyd,感觉还是有点麻烦,用法有点别扭。
还是自己从源码下手,既然能调用指定的spider,为什么不能同时执行多个spider呢?
在spider的parse(self, response)处设置一个断点,查看调用堆栈,
看上图中的调用堆栈,从顶至下一级一级的看代码,在crawl.py line55行处看到如下代码
def run(self, args, opts): if len(args) < 1: raise UsageError() elif len(args) > 1: raise UsageError("running 'scrapy crawl' with more than one spider is no longer supported") spname = args[0]
“running ‘scrapy crawl’ with more than one spider is no longer supported”看到这里没有,这里限制了spider的数量,将其修改成如下
def run(self, args, opts): if len(args) < 1: raise UsageError() # elif len(args) > 1: # raise UsageError("running 'scrapy crawl' with more than one spider is no longer supported") # spname = args[0] for spname in args: self.crawler_process.crawl(spname, **opts.spargs) self.crawler_process.start()
然后crawl ThirtySix One Two就可以同时执行三个ThirtySix 、One 、Two三个spider了,
但是三个spider公用的是一个setting.py文件,这个还需要再研究,看能不能每个spider都用自己的setting文件。
阅读全文
0 0
- 关于SCRAPY运行多个SPIDER的问题
- scrapy的spider
- 关于Scrapy 自定义Spider Middleware中遇到的坑
- Scrapy 的 Spider 的编写
- 同时运行多个scrapy爬虫的几种方法(自定义scrapy项目命令)
- 同时运行多个scrapy爬虫的几种方法(自定义scrapy项目命令)
- Spider之Scrapy安装的方法详解
- 让Scrapy的Spider更通用
- 运行Scrapy项目结果出错:KeyError: ‘Spider not found:
- Scrapy:一次性运行多个Spiders
- Scrapy:一次性运行多个Spiders
- spider的问题点
- scrapy爬虫运行问题
- Scrapy 运行 Tutorial 问题
- Scrapy spider代码片段
- Scrapy Spider前奏
- scrapy 入门教程 爬虫 Spider
- Spider based on scrapy
- 技术文章 | Weex Android 动画揭秘
- Ubuntu中修改grub重启出现 Memtest86 解决方法
- hdu 6134 素数打表一整套mark
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) E Cards Sorting
- InputStream的三个read的区别
- 关于SCRAPY运行多个SPIDER的问题
- PHP中的日期和时间函数
- Ant Trip HDU
- Vue 实现登录拦截(一)
- 常用Python模块下载网站
- linux常用命令总结
- kubernetes学习记录(8)——中文界面版dashboard安装
- 关于cnn的一点理解
- java中JVM的原理