deephotel icon indicating copy to clipboard operation
deephotel copied to clipboard

UnboundLocalError: local variable 'url' referenced before assignment

Open manentai opened this issue 5 years ago • 1 comments

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

manentai avatar Jan 28 '20 17:01 manentai