With this code i am trying to extract text from a table called "Last matches" in this webpage
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
url = 'https://s5.sir.sportradar.com/sports4africa/en/1/season/80526/headtohead/334075/340986/match/27195664'
driver = webdriver.Edge("C:/Users/Hama/Documents/msedgedriver.exe")
driver.get(url)
driver.implicitly_wait(10)
WebDriverWait(driver, 15).until(EC.presence_of_all_elements_located((By.XPATH, "//strong[text()='Last matches']/ancestor::div[6]//tbody/tr")))
rows= driver.find_elements_by_xpath("//strong[text()='Last matches']/ancestor::div[6]//tbody/tr")
All_last_matches = []
for res in rows:
score = res.find_element_by_xpath(".//td[5]//div[@class=' no-wrap']").get_attribute("innerText")
All_last_matches.append(score)
print(All_last_matches)
It gives me this list:
All_last_matches = ['2:0', '0:4', '3:4', '2:2', '0:1', '3:0', '2:0', '0:4', '1:0', '2:1', '1:1', '1:2']
How can i modify my code to get two lists like this:
Last_matches_team1 = ['2:0', '0:4', '3:4', '2:2', '0:1', '3:0']
Last_matches_team2 = ['2:0', '0:4', '1:0', '2:1', '1:1', '1:2']
I tried this:
Last_matches_team1 = All_last_matches[0:6]
Last_matches_team2 = All_last_matches[6:len(All_last_matches)]
But this will work only if the table1 have 6 rows, sometimes there is just 5 rows (5matches played)
Help is apprciated, thanks to all of you