2016-05-16 30 views
0

私は、各アイテムに対して2つの数量をクロールするスクラピースパイダーを持っています。問題は、floatメソッドを使用する必要があることです。そのため、クロールされたフィールドの1つが空の場合、エラーが発生し、スパイダーはそのページの要素のクロールを停止し、次のページに直接進みます。詐欺、エラーの後にクロールを続ける

エラーが発生した後でも、スクラップがクロールを続けるように指示する可能性はありますか?これは私のスパイダーのコードです。ありがとう!

def parse(self, response): 
    for sel in response.xpath('//li[@class="oneclass"]'): 
     item = exampleItem() 
     item['quant1'] = float(sel.xpath('a/div/span[@class="exampleclass"]/span[@class="amount"]/text()')) 
     item['quant2'] = float(sel.xpath('div[@class="otherexampleclass"]/input/@max')) 
     yield item 

答えて

3

あなたはtry/exceptブロックでラップできます。

def parse(self, response): 
    for sel in response.xpath('//li[@class="oneclass"]'): 
     try: 
      item = exampleItem() 
      item['quant1'] = float(sel.xpath('a/div/span[@class="exampleclass"]/span[@class="amount"]/text()')) 
      item['quant2'] = float(sel.xpath('div[@class="otherexampleclass"]/input/@max')) 
      yield item 
     except: 
      print "could not crawl {}".format(sel) 
+0

パーフェクト、それは私が探していたものです。私は正しいとマークします。 – Joe82

関連する問題