简体   繁体   English

如何修复错误:列表索引超出范围?

[英]How to fix error: list index out of range?

I cant solve this problem.我无法解决这个问题。 I really need help我真的需要帮助

here is my code: https://dpaste.org/PqpYE#L33这是我的代码: https ://dpaste.org/PqpYE#L33

here is the error that I am having:这是我遇到的错误:

File "test.py", line 30, in <module>
percent = soup.find('tbody').find_all('tr')[a].find('td').find_all(class_ ='styled__PercentContainer-sc-1qtnlbe-0 eeuaGk')
IndexError: list index out of range

Shift a+=1 to end of loop .a+=1移到loop结束。 Python indexing start with 0. Python 索引从 0 开始。

您可以通过for a, i in enumerate(row):来遍历行和索引,然后您不需要手动计算索引(您可以删除a+=1和初始化a=10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM