scrapy多个爬虫同时运行

news/2024/7/19 12:19:51 标签: 爬虫, python

运行爬虫

python">import  datetime as dt
#同时爬取
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
file_name_A="爬虫A"+dt.datetime.now().strftime('%Y-%m-%d') +".json"
file_name_B="爬虫B"+dt.datetime.now().strftime('%Y-%m-%d') +".json"

settings = get_project_settings()
crawler = CrawlerProcess(settings)
#参数 输出结果文件
spargs_A ={'-o':file_name_A}
spargs_B ={'-o':file_name_B}
crawler.crawl('爬虫A',spargs_A )
crawler.crawl('爬虫B',spargs_B )

crawler.start()
crawler.start()

爬虫运行参数
在这里插入图片描述

不同爬虫设置不同的pipeline

方法1

python">class CrawlersPipeline:
    def process_item(self, item, spider):
        if spider.name in ['爬虫A','爬虫B'] :
            return item

方法2 用custom_setting配置。

python">ITEM_PIPELINES = {
    'medicine_crawlers.pipelines.ACrawlersPipeline': 300,
    'medicine_crawlers.pipelines.BCrawlersPipeline': 300,
}

爬虫A的spider文件里

python">class longyi_spider(scrapy.Spider):
    name = '***'
    allowed_domains = ['***.com']
    start_urls = ['***']
    custom_settings={
    'ITEM_PIPELINES':{medicine_crawlers.pipelines.ACrawlersPipeline}
    } 

爬虫B格式同上


http://www.niftyadmin.cn/n/1093797.html

相关文章

poj1830:开关问题

链接:http://poj.org/problem?id1830 某天“佐理慧学姐”突然来问了我这道题。 诶,窝只会线性基,但是好像搞不了方案数啊…… 啃题解吧。 woc!线性代数哦,就是那种我不会的东西么。 矩阵的秩是啥啊……自由元又是啥啊…

常用的第三方库,感觉挺实用的,学习学习在做项目的时候可以达到事半功倍的效果,有兴趣的可以收藏一下,赠人收留余香。...

安全加密:https://github.com/liufan321/NSString-Hash 上拉/下拉刷新:https://github.com/itheima-developer/HMRefresh 照片选择:https://github.com/itheima-developer/HMImagePicker 交互式图像浏览:https://github.com/itheima-developer/HMPhotoBrowser 二维码…

selinum介绍与实践

介绍 selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requests无法直接执行JavaScript代码的问题 。 selenium本质是通过驱动浏览器,完全模拟浏览器的操作,比如跳转、输入、点击、下拉等,来拿到网页渲染之后的结果&#xff…

闲来写下感慨

自动化 webdriver 一些摘要 firefox public WebDriver driver; public void startFirefox(){ driver new FirefoxDriver(); }// 先声明后定义 初始化启动火狐浏览器// 下面最大化 关闭窗口 public void maxBrowse(){ driver.manage().window().m…

css_样式样式器的分类

详情:http://www.w3school.com.cn/h.asp 1、标签样式器:此样式器仅对html页面中div标签有效果 div{background-color: rosybrown;font-size:20px;}2、class样式器:此样式器仅对html页面中classcs有效果 .cs{ background-color: #0095bb; font…

request简单使用与报错记录

介绍 参考: request中文官方文档-简单上手 使用方法 有get和post请求 import requests response requests.post(url"", headers{}, timeout180,json{}) response requests.get(url"", headers{}, timeout180,json{}) …

Ubuntu 安装php+mysql 环境

新系统安装完毕后,首先运行apt-get update 更新apt库。 然后安装ssh,输入apt-get install openssh-server,安装ssh是为了可以远程操作,不然坐在机房实在太冷了。 ok,ssh远程连接成功。 第一步 安装mysql 输入sudo apt-get install mysql-serv…

java socket客户端连接服务端简单示例

本例只做简单功能演示,代码并不严谨,只是说明客户端如何实现连接服务端简单代码。 代码在集成Eclipse工具下测试编译运行环境如下图所示: 客户端echoClient.java代码: 1 package com.zhengzz.echo;2 3 import java.io.BufferedRea…