爬虫部分返回空值报错如何解决?

问题遇到的现象和发生背景

下面是2个产品的价格

img

问题相关代码,请勿粘贴截图
            final_price = li.xpath('.//span[@class="price"]/text()')[0]
            pre_price = li.xpath('.//span[@class="price-rrp__price"]/text()')[0]
            if len(pre_price)==0:
                print("list is  empty")
            else:
                pre_price = li.xpath('.//span[@class="price-rrp__price"]/text()')[0]
            print(final_price, pre_price)

运行结果及报错内容

17,98 € 29,99 €
完成
44,00 € 54,99 €
完成
160,08 € 194,99 €
完成
Traceback (most recent call last):
File "C:\Users\86134\PycharmProjects\pythonProject\use_kuaidaili.py", line 56, in
pre_price = li.xpath('.//span[@class="price-rrp__price"]/text()')[0]
IndexError: list index out of range

我的解答思路和尝试过的方法

返回有些结果是空值,但是出现报错。是不是用try else?谢谢

我想要达到的结果

直接检查返回结果不用去列表某个值。后面结果分别才进行赋值。