python绿色版spider的idle_Python-Scrapy Spider没有收到spider_idle信号
我有蜘蛛使用meta处理链中的请求,以产生具有来自多个请求的数据的项目.
我用来生成请求的方式是在首次调用parse函数时启动所有请求,但是,如果我有太多链接无法请求,则并不是所有请求都已计划好,最终我也无法获得所需的一切.
为了解决这个问题,我正在尝试使Spider一次请求5个产品,然后在Spider空闲时再次请求(通过在from_crawler中连接信号).
问题是,由于我的代码现在正确,spider_idle没有运行请求函数,并且蜘蛛立即关闭.好像蜘蛛不会闲置.
这是一些代码:
class ProductSpider(scrapy.Spider):
def __init__(self, *args, **kwargs):
super(ProductSpider, self).__init__(*args, **kwargs)
self.parsed_data = []
self.header = {}
f = open('file.csv', 'r')
f_data = [[x.strip()] for x in f]
count=1
first = 'smth'
for product in f_data:
if first != '':
header = product[0].split(';')
for each in range(len(header[1:])):
self.header[header[each+1]] = each+1
first = ''
else:
product = product[0].split(';')
product.append(count)
count+=1
self.parsed_data.append(product)
f.close()
@classmethod
def from_crawler(cls, crawler, *args, **kwargs):
spider = super(ProductSpider, cls).from_crawler(crawler, *args, **kwargs)
crawler.signals.connect(spider.request, signal=signals.spider_idle)
return spider
name = 'products'
allowed_domains = [domains]
handle_httpstatus_list = [400, 404, 403, 503, 504]
start_urls = [start]
def next_link(self,response):
product = response.meta['product']
there_is_next = False
for each in range(response.meta['each']+1, len(product)-1):
if product[each] != '':
there_is_next = True
yield scrapy.Request(product[each], callback=response.meta['func_dict'][each], meta={'func_dict': response.meta['func_dict'],'product':product,'each':each,'price_dict':response.meta['price_dict'], 'item':response.meta['item']}, dont_filter=True)
break
if not there_is_next:
item = response.meta['item']
item['prices'] = response.meta['price_dict']
yield item
#[...] chain parsing functions for each request
def get_products(self):
products = []
data = self.parsed_data
for each in range(5):
if data:
products.append(data.pop())
return products
def request(self):
item = Header()
item['first'] = True
item['sellers'] = self.header
yield item
func_dict = {parsing_functions_for_every_site}
products = self.get_products()
if not products:
return
for product in products:
item = Product()
price_dict = {1:product[1]}
item['name'] = product[0]
item['order'] = product[-1]
for each in range(2, len(product)-1):
if product[each] != '':
#print each, func_dict, product[each]
yield scrapy.Request(product[each], callback=func_dict[each],
meta={'func_dict': func_dict,'product':product,
'each':each,'price_dict':price_dict, 'item':item})
break
raise DontCloseSpider
def parse(self, response=None):
pass
python绿色版spider的idle_Python-Scrapy Spider没有收到spider_idle信号相关推荐
- 七月算法课程《python爬虫》第五课: scrapy spider的几种爬取方式
本节课介绍了scrapy的爬虫框架,重点说了scrapy组件spider. spider的几种爬取方式: 1.爬取1页内容 2.按照给定列表拼出链接爬取多页 3.找到'下一页'标签进行爬取 4.进入链 ...
- python绿色版使用_嵌入式Python : 如何在U盘安装绿色版 Python
一直以来都习惯将各种日常工具和开发环境变为绿色版. portable,一个U盘就能将日常所用到的开发环境和必备资料随身携带,从公司到家里,再也不用背上重重的笔记本,通勤路上也能轻轻松松的听听音乐,看看 ...
- python绿色版_mPython最新下载_mPython绿色版 - 软件帝
mPython官方版是款针对程序员们所打造的图形编程工具.mPython电脑版支持命令式程序设置,并具有强大的编程库,用户可将其与多种模块完美相结合在一起.mPython还可以支持函数,仿真.hex. ...
- python绿色版运行程序_Python打包exe运行程序,分享你的技术成果!
本文转载于公众号:你想要
- python学习笔记之爬虫框架scrapy(十七)
一.安装 执行以下命令安装scrapy pip install scrapy 注意: Scrapy是用纯Python编写的,并且依赖于一些关键的Python包(以及其他一些包): lxml,高效的XM ...
- scrapy.Spider的属性和方法
scrapy.Spider的属性和方法 属性: name:spider的名称,要求唯一 allowed_domains:允许的域名,限制爬虫的范围 start_urls:初始urls custom_s ...
- 安装Python(绿色版)
前言:在Win10系统中安装Python环境,使用安装包有些麻烦,使用嵌入版则仅需解压并配置环境变量即可,省时省力,十分方便.同时还安装包管理器pip. 下载嵌入版 官网下载:Python嵌入版 解压 ...
- python 实时数据推送_python scrapy 爬取金十数据并自动推送到微信
一.背景 因业务需要获取风险经济事件并采取应对措施,但因为种种原因又疏忽于每天去查看财经日历,于是通过爬取金十数据网站并自动推送到微信查看. 二.目标实现 image 三.环境与工具 1.pychar ...
- Python爬虫——零基础实现基于scrapy框架的项目
1. 生成器 yield作用 : 把一个函数当做一个生成器使用 斐波那契数列: def fib(n):a, b, s = 0, 1, 0while s<n:a, b = b, a+bs += 1 ...
最新文章
- HTML表格中的nowrap
- php 输出带参数整个html页面,如何在PHP页面中原样输出HTML代码(是该找本php的数来看了)...
- 无线路由器——多路由器无线桥联解决方案
- arcgis工具_地理工具学习--arcgis篇(16):标准距离
- jquery-幻灯片效果-编辑中
- C# 使用Bitmap类进行图片裁剪
- CentOS7——安装JDK和Tomcat
- c语言程序下三子棋,C语言实现三子棋游戏(初级版)
- Spring:pom.xml中引入依赖发红解决方案
- 中国有多少家银行 最全名单统计
- JS新特性和流行框架 - 跟着李南江学编程
- 12306GT多线程、分流免费抢票工具使用
- 人生性格、爱情与酒场哲学
- html5积分墙联盟,积分墙平台有哪些(全面解读积分墙)
- 计算机ppt测试题填空题,2017职称计算机PowerPoint练习试题及答案(1)-中华考试网...
- 使用KMS批量激活操作系统
- 实战揭露360和QQ医生系统漏洞检测真相!
- Stratifyd AI: 5,300万数据,800万用户,利用垂直论坛评论绘制精准用户性格画像
- html中设置浏览器解码方式
- PYTHON图形及图形界面相关
热门文章
- Storage Access API 介绍
- 解决springboot跨域问题No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
- 漏洞挖掘——实验3 Race_Condition
- 【知识点】eCall是什么?
- 钉钉支持鸿蒙系统,钉钉鸿蒙版app
- cer pem 证书转换_证书cer格式转为pem格式
- OpenGL技术之View Volume, Viewport, Screen的关系
- 面试系列一:简历之 简历包含哪些内容
- webpack打包优化之moment语言包优化moment-locales-webpack-plugin
- matlab控制系统仿真论文,基于MATLAB的异步电动机直接转矩控制系统仿真毕业论文...