How to use IF statement inside yield section in scrapy?

Viewed 31

How can I use the IF statement inside the yield section in scrapy? For example_

If "image_urls_1" is found yield "image_url_1", else "image_urls_2". What will be the appropriate method?

yield {
            'image_urls_1': response.xpath("//div[@id='itemslider-zoom']//a/@href").getall()
            'image_urls_2': response.xpath("//*[@id='image-main']/@src").getall()
        }
0 Answers
Related