//a[contains(@class,'inprogress')] - selects active matches
//span[contains(@itemprop,'name')] - selects all matches
How do I select only matches that aren't active? (atctives are red colored)
https://www.fudbal91.com/previews/2022-03-30
CodePudding user response:
You can use not()
like
//a[not(contains(@class,'inprogress'))]
And if you want use both then use then both together
//a[not(contains(@class,'inprogress'))]//span[contains(@itemprop,'name')]
from selenium import webdriver
from selenium.webdriver.common.by import By
#from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.firefox import GeckoDriverManager
import time
url = 'https://www.fudbal91.com/previews/2022-03-30'
#driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
driver.get(url)
time.sleep(2)
all_items = driver.find_elements(By.XPATH, '//a[not(contains(@class,"inprogress"))]//span[contains(@itemprop,"name")]')
print('len(all_items):', len(all_items))
for item in all_items:
print(item.text)