Python Scrapy,出错后继续爬行
我有一只痒痒的蜘蛛,每样东西爬两次。问题是,我必须使用Python Scrapy,出错后继续爬行,python,scrapy,scrapy-spider,Python,Scrapy,Scrapy Spider,我有一只痒痒的蜘蛛,每样东西爬两次。问题是,我必须使用float方法,因此当爬网的某个字段为空时,我会得到一个错误,爬行器停止爬网该页面中的元素,并直接进入下一页 有没有可能让scrapy在出错后继续爬行?这是我的蜘蛛的密码。谢谢 def parse(self, response): for sel in response.xpath('//li[@class="oneclass"]'): item = exampleItem() item['quant1
float
方法,因此当爬网的某个字段为空时,我会得到一个错误,爬行器停止爬网该页面中的元素,并直接进入下一页
有没有可能让scrapy在出错后继续爬行?这是我的蜘蛛的密码。谢谢
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
您可以将其包装在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)
您可以将其包装在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)
太好了,这就是我想要的。我认为它是正确的。完美的,这就是我想要的。我认为它是正确的。