scrapy多線程文件下載
阿新 • • 發佈:2017-07-12
spi clas 下載 數據 all 有時 文件存儲 setting ()
在爬取數據時有時候有些文件數據需要爬取下載下來使用多線程下載可以讓程序跑的更快點。
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
scrapy多線程文件下載