Does scrapy have its own method of downloading files when downloading files? Download??

excuse me, does the scrapy download file have its own download? Or write a new download yourself?

Jun.24,2021

Yes, scrapy comes with three Pipeline of file,image,media
take file download as an example:
1. Import FilesPipeline: from scrapy.pipelines.files import FilesPipeline
2 in the pipelines module Enable: ITEM_PIPELINE= {'scrapy.pipelines.files.FilesPipeline':1}
3 in the configuration file In the configuration file configuration download directory FILES_STORE='/user/somepath'
4. Define two key fields in the items module:

class ExamplesItem(scrapy.Item):
    file_urls=scrapy.Field()
    files=scrapy.Field()

5. In siper, you only need to add the URL to be downloaded to the Item instance:

    def parse(self,response):
        download_url=response.css('a::attr(href)').extract_first()-sharpurl
        item=ExamplesItem()
        item['file_urls']=[download_url]
        yield item

6. Just start sipder.

Menu