爬蟲時出現 IndexError: list index out of range 的原因

爬蟲時出現 IndexError: list index out of range 的原因有兩種:

簡單舉例如下:

第一種情況: index越界

Alex = [1,2,3]
Alex[1]
2
Alex[0]
1
Alex[2]
3
Alex[3]
Traceback (most recent call last):
  File "<input>", line 1, in <module>
IndexError: list index out of range

 

第二種情況:列表爲空
Eric = []
Eric[1]
Traceback (most recent call last):
  File "<input>", line 1, in <module>
IndexError: list index out of range
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章