Selenium 无法在使用 Python 时单击“获取数据"按钮

编程入门 行业动态 更新时间:2024-10-28 20:21:00
本文介绍了Selenium 无法在使用 Python 时单击“获取数据"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在从这个网站抓取数据.元素在下面和 geckodriver

I am scraping data from this website . The element is below and geckodriver

<img class="getdata-button" style="float:right;" src="/common/images/btn-get-data.gif" id="get" onclick="document.getElementById('submitMe').click()">

但无法让 selenium 点击它,甚至尝试过 xpath、id 但不是运气是否有任何修复或解决方法来完成它?

but can't get selenium to click it tried even xpath, id but not luck is there any fix or work around to get it done?

推荐答案

要单击元素 Get Data,您可以使用以下任一定位器策略:

To click on the element Get Data you can use either of the following Locator Strategies:

  • 使用css_selector:

driver.find_element_by_css_selector("img.getdata-button#get").click()

  • 使用xpath:

    driver.find_element_by_xpath("//img[@class='getdata-button' and @id='get']").click()

  • 理想情况下,要单击需要诱导的元素 WebDriverWait 用于 element_to_be_clickable(),您可以使用以下任一定位器策略:

    Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

    • 使用CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "img.getdata-button#get"))).click()

  • 使用XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//img[@class='getdata-button' and @id='get']"))).click()

  • 注意:您必须添加以下导入:

  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait from selenium.webdrivermon.by import By from selenium.webdriver.support import expected_conditions as EC

  • 更多推荐

    Selenium 无法在使用 Python 时单击“获取数据"按钮

    本文发布于:2023-11-10 01:38:47,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1574006.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:单击   按钮   数据   Selenium   Python

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!