在爬取数据时有时候有些文件数据需要爬取下载下来使用多线程下载可以让程序跑的更快点。

scrapy中有个扩展可以使用扩展模块来实现下载。

在自己的spider中加入 custom_settings 

class MytestSpider(scrapy.Spider):
    name = "mytest"
    custom_settings = {
        'EXTENSIONS': { #设在拓展
            'mymidtest.mydownutils.extension.SpiderOpenCloseLogging': 500,  
        },
        'MYEXT_ENABLED': True, #打开拓展
    }
'mymidtest.mydownutils.extension.SpiderOpenCloseLogging'为项目路劲下的mydownuils包
在ini函数中加入
    def __init__(self, ):
        .........
        .........
        self.myredis = operatRedis(self.name)
        self.Redis = self.myredis.get_instent()

在要下载的时候添加

self.myredis.add_url_filepath(self.Redis,url,filepath_all)
url为下载url地址,filepath_all文件存储地址
这样工具包就配置好可以下载了


工具包地址
github地址:https://github.com/sea1234/pyScrapyDownUtils

 

相关文章:

  • 2021-06-04
  • 2022-12-23
  • 2021-11-18
  • 2021-09-25
  • 2022-01-13
  • 2021-12-10
  • 2021-12-10
猜你喜欢
  • 2021-08-20
  • 2021-06-20
  • 2022-12-23
相关资源
相似解决方案