2016-03-25 15 views
1

Scrapyを使用して、抽出したURLを使用してバイナリファイルをメモリに読み込んで内容を抽出します。Scrapyを使用してファイルストリームを読み込み用に開くにはどうすればよいですか?

現在のところ、ページのセレクタを使用してURLを見つけることができます。

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

このファイルをメモリに読み込むと、そのファイルのコンテンツを探すことができますか?

感謝

答えて

0

要求を作成し、コールバックでコンテンツを探る:

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) 
+0

パーフェクト。ありがとうございました!治療はとても簡単です。 –

関連する問題