def parse_department(self, response):
    products = response.css('ul.productLister.gridView').extract()
    if products:
        for product in self.handle_product_listing(response):
            (yield product)
    pages = response.css('ul.categories.shelf li a::attr(href)').extract()
    if (not pages):
        pages = response.css('ul.categories.aisles li a::attr(href)').extract()
    if (not pages):
        return
    for url in pages:
        (yield response.follow(url, callback=self.parse_department))
def parse_department(self, response):
    products = response.css('ul.productLister.gridView').extract()
    if products:
        for product in self.handle_product_listing(response):
            (yield product)
    pages = response.css('ul.categories.shelf li a::attr(href)').extract()
    if (not pages):
        pages = response.css('ul.categories.aisles li a::attr(href)').extract()
    if (not pages):
        return
    for url in pages:
        (yield response.follow(url, callback=self.parse_department))