Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用Scrapy打开文件流进行读取?_Python_Scrapy_Scrapy Spider - Fatal编程技术网

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

Python 如何使用Scrapy打开文件流进行读取?,python,scrapy,scrapy-spider,Python,Scrapy,Scrapy Spider,使用Scrapy,我想使用提取的url将二进制文件读入内存并提取内容 目前,我可以使用选择器在页面上找到URL,例如 myFile = response.xpath('//a[contains(@href,".interestingfileextension")]/@href').extract() 然后如何将该文件读入内存,以便查找该文件中的内容 非常感谢提出请求并浏览回调中的内容: def parse(self, response): url = response.xpath('/

使用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)

发出请求并浏览回调中的内容:

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)

完美的非常感谢。刮痧使它很容易。完美。非常感谢。刮痧使它很容易。