Nov-07-2019, 08:07 PM
(This post was last modified: Nov-07-2019, 08:07 PM by kozaizsvemira.)
Now I'm not sure what you are trying to do, but here's working code
Your first error came when you are calling soup you call it from var soup not last var you called soup.
You did:
And please use spaces between = and ,
Hope it helps.
Your first error came when you are calling soup you call it from var soup not last var you called soup.
You did:
tbody=leaderboard.find('tbody')You need:
tbody = soup.find('tbody')And you will get second error list index out of range unless you change [1] and [1] to [0] and [0] like in code below.
And please use spaces between = and ,
Hope it helps.
import requests from bs4 import BeautifulSoup data=requests.get('https://umggaming.com/leaderboards') soup=BeautifulSoup(data.text, 'html.parser') leaderboard = soup.find('div', { 'id': 'leaderboard-table' }) tbody = soup.find('tbody') for tr in soup.find_all('tr'): place=tr.find_all('td')[0].text.strip() username=tr.find_all('td')[0].find_all('a')[0].text.strip() xp=tr.find_all('td')[0].text.strip() print(place, username, xp)I'm assuming by having [1] in your code you are trying to identify second element of <td> ? If so it won't work with [] I use re findall