# -*- coding: utf-8 -*-
# Define here the models for your spider middleware
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/spider-middleware.html
from scrapy import signals
class ImmocSpiderMiddleware(object):
# Not all methods need to be defined. If a method is not defined,
# scrapy acts as if the spider middleware does not modify the
# passed objects.
@classmethod
def from_crawler(cls, crawler):
# This method is used by Scrapy to create your spiders.
s = cls()
crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)
return s
def process_spider_input(self, response, spider):
# Called for each response that goes through the spider
# middleware and into the spider.
# Should return None or raise an exception.
return None
def process_spider_output(self, response, result, spider):
# Called with the results returned from the Spider, after
# it has processed the response.
# Must return an iterable of Request, dict or Item objects.
for i in result:
yield i
def process_spider_exception(self, response, exception, spider):
# Called when a spider or process_spider_input() method
# (from other spider middleware) raises an exception.
# Should return either None or an iterable of Response, dict
# or Item objects.
pass
def process_start_requests(self, start_requests, spider):
# Called with the start requests of the spider, and works
# similarly to the process_spider_output() method, except
# that it doesn’t have a response associated.
# Must return only requests (not items).
for r in start_requests:
yield r
def spider_opened(self, spider):
spider.logger.info('Spider opened: %s' % spider.name)
class ImmocDownloaderMiddleware(object):
# Not all methods need to be defined. If a method is not defined,
# scrapy acts as if the downloader middleware does not modify the
# passed objects.
@classmethod
def from_crawler(cls, crawler):
# This method is used by Scrapy to create your spiders.
s = cls()
crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)
return s
def process_request(self, request, spider):
# Called for each request that goes through the downloader
# middleware.
# Must either:
# - return None: continue processing this request
# - or return a Response object
# - or return a Request object
# - or raise IgnoreRequest: process_exception() methods of
# installed downloader middleware will be called
return None
def process_response(self, request, response, spider):
# Called with the response returned from the downloader.
# Must either;
# - return a Response object
# - return a Request object
# - or raise IgnoreRequest
return response
def process_exception(self, request, exception, spider):
# Called when a download handler or a process_request()
# (from other downloader middleware) raises an exception.
# Must either:
# - return None: continue processing this exception
# - return a Response object: stops process_exception() chain
# - return a Request object: stops process_exception() chain
pass
def spider_opened(self, spider):
spider.logger.info('Spider opened: %s' % spider.name)
三斤和他的朋友们
- 粉丝: 25
- 资源: 4
最新资源
- python使用mysql基础教程
- COMSOL模型 锂离子电池热管理 电化学热耦合模型 风冷热 相变热 模型仅适用于comsol-5.5及更高版本,本人实测模型有效可运行
- python使用mysql基础教程
- 北京神州云合数据科技发展有限公司创投信息
- 三菱FX1N与台达MS300变频器485通讯程序 可直接拿来实用了,三菱FX PLC与台达变频器modbus RTU通讯 采用器件:三菱FX1N 24MT PLC,1个FX1N 485BD板,1个台达
- 西门子气力输送系统SMART200PLC程序,用SMART1000画面组态,画面软件打开需WINCC flexible SMARTV3SP2 D4 程序2为西门子1200和昆仑通泰触摸屏物料输送程序
- 欧姆龙CP1H CIF11与东元Teco N310变频器通讯实战程序 功能:原创程序,可直接用于现场程序 欧姆龙CP1H的CIF11通讯板,实现对东元Teco N310变频器 设定频率,读取
- 海思瑞格(医疗用可穿戴设备研发商,北京海思瑞格科技有限公司)创投信息
- 基于粒子群算法的储能优化配置 建立了储能的成本模型,包含运行维护成本以及容量配置成本,然后以该成本函数最小为目标函数,经过粒子群算法求解出其最优运行计划,并通过其运行计划最终确定储能容量配置的大小,求
- 三菱FX1N与东元Teco N310变频器通讯实战程序 可直接拿来实用了,三菱FX PLC与东元N310变频器modbus RTU通讯 采用器件:三菱FX1N 24MT PLC,1个FX1N
- Rainbow-8.1.0-Server&Agent
- 使用 MySQL Connector和Python 进行数据库操作的示例代码.pdf
- 两阶段鲁棒优化模型 多场景 采用matlab编程两阶段鲁棒优化程序,考虑四个场景,模型采用列与约束生成(CCG)算法进行求解,场景分布的概率置信区间由 1-范数和∞-范数约束,程序含拉丁超立方抽样+k
- 三菱FX3U 485BD与3台施耐德ATV 71变频器通讯程序 程序为原创,稳定可靠,有注释 并附送程序,有接线方式,设置 同时实现变频器 DRIVECOM流程,解决施耐德ATV变频器断
- 解决Navicat连接数据库报错"ORA-12545"问题-通用的oci.dll
- 中国电信业人工智能行业应用发展图谱(2024).pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈