0

I want to get players name on the https://www.premierleague.com/match/22720.

HTML code :

'Player Name' = each player on the website

<div class="info"><span class="name">'Player Name'<div class="playerLineupEventContainer-4664"></div></span>

My code :

match_players = match_player_wd.find_elements_by_class_name('info')

len(match_players) = 36

I just need 11 players name of 'Tottenham'. But I don't know how to get names.

2 Answers 2

1

Can you try the following:

player_elem = match_player_wd.find_elements_by_class_name('name')
player_names = [e.text for e in player_elem]

I did not take a look at the source of the page, so it may not be as direct as just selecting all elements with the "name" class. In that case, you probably need to set the 'info' class element as the root first and fetch its children by the same find_by_class_name() function.

Sign up to request clarification or add additional context in comments.

Comments

0

There are two type of players :

  1. Home Player.
  2. Away Player.

You can try with this code to get players name :

driver = webdriver.Chrome(executable_path = r'driver_path')
wait = WebDriverWait(driver,10)

driver.maximize_window()

driver.get("https://www.premierleague.com/match/22720")

wait = WebDriverWait(driver, 10)

wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.scoreboxContainer')))

home_players = driver.find_elements_by_css_selector('div.home div.event')

for home_player in home_players:
  print(home_player.text)

away_players = driver.find_elements_by_css_selector('div.away div.event')

for away_player in away_players:
  print(away_player.text)

Hope this will help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.