![](/img/trans.png)
[英]Selenium Python find text on page and click next ahref link
[英]Selenium Python click link on page by text/style
目前正在瀏覽 bet365.com 網站,我遇到了一些停頓。 我關心的頁面有以下URL; https://www.bet365.com/#/AS/B2/ 。
此頁面列出了當天的所有賽馬...我希望單擊其中一個鏈接。 源碼 html 可以在下面找到;
< div class ="slm-RaceMeeting slm-RaceMeeting_Uk " >
< div class ="slm-MeetingHeader " >
< div class ="slm-MeetingHeader_LeftContainer " >
< div class ="slm-MeetingHeader_RaceName " style="" > Ascot < / div >
< div class ="slm-RaceMeeting slm-RaceMeeting_Uk " >
< div class ="slm-RaceMeeting slm-RaceMeeting_Uk " >
< div class ="slm-RaceMeeting slm-RaceMeeting_Uk " >
< div class ="slm-RaceMeeting slm-RaceMeeting_Uk " >
所有比賽名稱都包含在 class = "slm-RaceMeeting slm-RaceMeeting_Uk " 但我找不到任何可單擊以導航到所需會議的按鈕或鏈接(例如導航到 ascot 會議)。
我嘗試了以下點擊;
browser.find_element_by_xpath("//*[contains(concat( " ", @class, " " ), concat( " ", "slm-
MeetingHeader_RaceName", " " ))]") .click()
browser.find_element_by_css_selector('.slm-MeetingHeader_RaceName').click()
...以及許多其他嘗試,但無法解決這個問題,幫助將是驚人的,非常感謝
我必須點擊我的方式進入賽馬,然后使用 xpath 如下所示(我收集了該部分中的所有結果,可以點擊不同時間的 Ascot)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
d = webdriver.Chrome()
d.get('https://www.bet365.com/#/AS/B2/')
d.find_element_by_css_selector("a").click()
racing = WebDriverWait(d,5).until(EC.presence_of_element_located((By.XPATH, '//*[@class="wn-Classification " and contains(text(),"Horse Racing")]')))
url = d.current_url
while True:
racing.click()
if d.current_url !=url: #might want to add timeout for this. Also, wait clickable doesn't seem to work. But explicit sleep does.
break
results = d.find_elements_by_xpath('//*[@class="slm-MeetingHeader_RaceName " and contains(text(),"Ascot")]/ancestor::div[@class="slm-RaceMeeting slm-RaceMeeting_Uk "]//*[@class="slm-UkRacingCouponLink_RaceNameTime "]')
results[0].click()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.