爬蟲時出現 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