在做 scrapy 爬蟲的時候遇到一個錯誤“IndexError: list index out of range”
百度了一下之後,又測試了一下,發現這種錯誤一般有兩種情況:
第一種可能情況:list[index] index超出範圍
In [4]: li = [1,2,3]
In [5]: li[3]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-5-26fad520b253> in <module>()
----> 1 li[3]
IndexError: list index out of range
第二種可能情況:list是一個空的,沒有一個元素
進行list[0]就會報該錯誤。
In [6]: li = []
In [7]: li[0]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-7-d8d39608afdb> in <module>()
----> 1 li[0]
IndexError: list index out of range