dimanche 28 janvier 2018

Python IF ELSE Statement Not Working - Scrapy [on hold]

My IF ELSE statement isn't working. If the first condition isn't met, the function throws an error and doesn't continue to the next part of the IF statement. I'm new to Python, any help offered is appreciated. Code is below:

    if response.css('div.hide-for-small:nth-child(4)::text'):
        price = response.css('div.hide-for-small:nth-child(4)::text').extract()[1].split()[0]
    elif response.css('div.product-price::text'):
        price = response.css('div.product-price::text').extract()[3].split()[0]
    else:
        price = response.css('div.product-price::text').extract()[5].split()[0]

Aucun commentaire:

Enregistrer un commentaire