Python 如何使用Scrapy打开文件流进行读取?
使用Scrapy,我想使用提取的url将二进制文件读入内存并提取内容 目前,我可以使用选择器在页面上找到URL,例如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('/
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)
完美的非常感谢。刮痧使它很容易。完美。非常感谢。刮痧使它很容易。