driver.get('https://www.tennis24.com/match/4xFaW6fP/#match-statistics;0')
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='statText statText titleValue' and text()='Aces']//following::div"))).text)
使用XPATH和get_attribute('innerHTML'):
driver.get('https://www.tennis24.com/match/4xFaW6fP/#match-statistics;0')
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='statText statText titleValue' and text()='Aces']//following::div"))).get_attribute('innerHTML'))
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
要打印文本4,需要为
visibility_of_element_located()
导出WebDriverWait,并且可以使用以下Locator Strategies之一:使用
XPATH
和文本属性:使用
XPATH
和get_attribute('innerHTML')
:注意:您必须添加以下导入:
相关问题 更多 >
编程相关推荐