deephotel
deephotel copied to clipboard
UnboundLocalError: local variable 'url' referenced before assignment
def parse_hotel(self, response):
try:
list_url = response.xpath('//a[@class="show_all_reviews_btn"]/@href')
url = response.urljoin(list_url[0].extract())
return scrapy.Request(url, callback=self.parse_score_scrape)
except:
return scrapy.Request(url, callback=self.parse)
I think this point is problematic: if the spider except, it will have to use url
, which is undefined... at least that's the error I get, every time a hotel has no reviews:
UnboundLocalError: local variable 'url' referenced before assignment