Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while printing (high_temps) #23

Open
ChongLC opened this issue Sep 2, 2020 · 5 comments
Open

Error while printing (high_temps) #23

ChongLC opened this issue Sep 2, 2020 · 5 comments

Comments

@ChongLC
Copy link

ChongLC commented Sep 2, 2020

high_temps = []
for row in rows:
tds = row.find_all('td')
for i in range(1,7):
high_temps.append(tds[i].text)
print(high_temps)


IndexError Traceback (most recent call last)
in ()
8 tds = row.find_all('td')
9 for i in range(1,7):
---> 10 high_temps.append(tds[i].text)
11 print(high_temps)

IndexError: list index out of range

@nehal6657
Copy link

can you tell me that in which file does this piece of code exists???

@ChongLC
Copy link
Author

ChongLC commented Sep 27, 2020

I was referring to Python/Web Data Mining/Python BeautifulSoup Web Scraping Tutorial.ipynb

@nehal6657
Copy link

okayy

@amitShindeGit
Copy link

Hey ChongLC,i have created a pull request which solves this issue.I am new to Git,so could you please tell me if my PR is correct,like can the author merge it now if only it is correct.

@AnuragNagare
Copy link

Try this

high_temps = []

for row in rows:
    tds = row.find_all('td')
    
    # Check the length of tds to ensure it's not empty
    if len(tds) >= 7:
        for i in range(1, 7):
            high_temps.append(tds[i].text)
    else:
        print("Not enough <td> elements in the row.")

print(high_temps)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants