如何使用 Scrapy 打开文件流进行读取?

How do you open a file stream for reading using Scrapy?

使用Scrapy,我想使用我提取的url将二进制文件读入内存并提取内容。

目前,我可以使用选择器在页面上找到 URL,例如

myFile = response.xpath('//a[contains(@href,".interestingfileextension")]/@href').extract()

然后如何将该文件读入内存以便我可以在该文件中查找内容?

非常感谢

发出请求并探索回调中的内容:

def parse(self, response):
    url = response.xpath('//a[contains(@href,".interestingfileextension")]/@href').extract_first()
    return scrapy.Request(url, callback=self.parse_file)

def parse_file(self, response):
    # response here is the contents of the file
    print(response.body)