Feb-10-2022, 07:25 PM
You get that error because you loop is wrong,so try to do a string slice.
Also it's not
Do not use
Also it's not
div
it's in a table th
tag.Do not use
try:except
when testing stuff out.from bs4 import BeautifulSoup import requests html = requests.get('https://fbref.com/en/squads/19538871/Manchester-United-Stats') html.raise_for_status() soup = BeautifulSoup(html.content, 'lxml') clubs = soup.find(class_='stats_table') players = clubs.find_all('th', {'data-stat': 'player'}) for name in players: print(name.text)
Output:Player
David de Gea
Bruno Fernandes
Harry Maguire
Scott McTominay
Fred
Cristiano Ronaldo
Mason Greenwood
Aaron Wan-Bissaka
Luke Shaw
....