You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Selenium Python定位LOAD MORE按钮?UFC运动员页面爬取按钮定位求助

解决UFC运动员页面「Load More」按钮定位问题

Hey Nick, let's work through that tricky "Load More" button targeting issue on the UFC athletes page. Based on the HTML snippet you shared, here are several reliable approaches to locate that element:

  • Class + Text Content Combination
    The button has a button class and the exact text "Load More" — combining these two traits makes for a precise locator. For example, in Selenium:
    driver.find_element(By.XPATH, "//a[@class='button' and text()='Load More']")
    If you're worried about extra whitespace or line breaks messing with exact text matches, use a contains check instead:
    driver.find_element(By.XPATH, "//a[@class='button' and contains(text(), 'Load More')]")

  • Leverage the rel Attribute
    Notice the button has rel="next" — this attribute is standard for pagination "next" actions, so it's a great target. You can use either XPath or CSS selectors:

    • XPath: driver.find_element(By.XPATH, "//a[@rel='next']")
    • CSS Selector: driver.find_element(By.CSS_SELECTOR, "a.button[rel='next']")
  • Href Parameter Filter
    The button's href includes a page= parameter, which you can use to narrow down the element:
    driver.find_element(By.XPATH, "//a[@class='button' and contains(@href, 'page=')]")

Quick Troubleshooting Tips

Don't forget these common pitfalls that might cause your locator to fail:

  • Dynamic Loading: The button might not appear immediately, so use explicit waits to ensure it's clickable before interacting. Here's a Selenium example:
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    wait = WebDriverWait(driver, 10)
    load_more_btn = wait.until(EC.element_to_be_clickable((By.XPATH, "//a[@class='button' and text()='Load More']")))
    
  • Iframe/Shadow DOM Check: Confirm the button isn't nested inside an iframe or shadow DOM. If it is, you'll need to switch contexts first before locating the element.

内容的提问来源于stack exchange,提问作者Nick_Lopez43

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 18:48:12