Im having a problem in scrapping a soccer team name with selenium. The problem is that the span class about the home team and away team is the same ("Nh")
<span class="Lh"> <span class="Nh" id="0-639478__match-row__home-team-name"> Estudiantes Merida </span> </span> <span class="Mh"> <span class="Nh" id="0-639478__match-row__away-team-name"> Universidad Central </span> </span>
How do i get the output : Home Team vs Away Team ? In this case is : Estudiantes Merida vs Universidad Central
I tried this :
teams_home = soup.find_all(‘span’, class_="Nh") print(teams_home)
i tried to find by ID too, but didnt work too. Any help please ?
URL : https://www.livescores.com/football/live/?tz=-3, editing sry i forgot
Your title says you are using Selenium in your title but your code snippet uses
soup which leads me to believe you are using Beautiful Soup. Either way however, it looks like your best bet would be to get the element with class name "Lh" and the element with the class name "Mh" then from there get the child’s text.
If using Selenium this worked for me:
driver.get('https://www.livescores.com/football/live/?tz=-3') WebDriverWait(driver, 60).until(lambda d: d.find_elements(By.CLASS_NAME, 'Lh')) first = driver.find_elements(By.CLASS_NAME, 'Lh') second = driver.find_elements(By.CLASS_NAME, 'Mh') for i, element in enumerate(first): print(first[i].text + ' vs ' + second[i].text)
If using BeautifulSoup this also worked for me:
page = requests.get('https://www.livescores.com/football/live/?tz=-3') soup = BeautifulSoup(page.content, 'html.parser') first = soup.find_all(class_='Lh') second = soup.find_all(class_='Mh') for i, element in enumerate(first): print(first[i].text + ' vs ' + second[i].text)
Both gave output:
CA Huracan vs Rosario Central Independiente vs Talleres Chapecoense AF vs Criciuma ASC San Diego vs California United
Answered By – Connor Dudley