Home > Software design >  How to fix error: list index out of range?
How to fix error: list index out of range?

Time:07-16

I cant solve this problem. I really need help

here is my code: 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

CodePudding user response:

Shift a =1 to end of loop. Python indexing start with 0.

CodePudding user response:

You can iterate through the row and index in tandem by doing for a, i in enumerate(row): then you don't need to count up the index manually (you can remove the a =1 and the initialization a=10.

  • Related