【问题标题】:how to click on different links of directory listing in a web page using selenium web-driver python如何使用selenium web-driver python单击网页中目录列表的不同链接
【发布时间】:2020-01-19 08:39:50
【问题描述】:

我正在抓取一个网站,我需要点击每个配置文件的每个按钮(立即查询)。我也尝试了下面的代码,但它显示了 ElementClickInterceptedException。

browser.driver.find_element_by_class_name("green-btn").first.click()

我附上了图片以供参考,还附上了源代码。

enter image description here

下面是检查元素代码-

<li class="book-btn">
<!-- <span class="dtsbtntxt">Book a Table</span> -->
<!--  <span class="inner_spr in_po"></span> -->
                       <!-- <a title="Book Doctor Appointment" class="bookap green-btn result_loader_3 big_dn" href="javascript:void(0);" onClick="showloader('result', 'result_loader_3', this); _ct('DBookAppointment', 'lspg', '2'); openDiv('best_deal_div', 'bestdeal', '', '9999PX744.X744.130617175155.L7U9', 5);"><i id="result_loader_3"></i>Enquire Now</a> -->
                                                                                                                                                            <a class="green-btn result_loader_3  wdb" onclick="_ct('gtlp', 'lspg'); showloader('result', 'result_loader_3', this); trackEvent('Get The Lowest Price', 'onclicklowestprice', 'Get The Lowest Price');  return openDiv('best_deal_div', 'bestdeal', '', '9999PX744.X744.130617175155.L7U9', 5);" href="javascript:void(0);"><i id="result_loader_3"></i>Enquire Now</a>
                                                                            <span flg="2" docid="9999PX744_X744_130617175155_L7U9" countvalue="0">

请帮助,如何使用 selenium 网络驱动程序单击每个按钮,我使用的是 chrome 网络驱动程序。

【问题讨论】:

  • 不要发布图片,因为它们通常没有用。可以分享一下实际的网址吗?如果你这样做,你会得到更多的回应/帮助。其次,你到底想要什么?您可能无需单击按钮即可获得所需内容,但由于不提供示例输出,我们无法了解您正在尝试做什么。
  • 其实我想点击带有“enquiry now”文本的每个按钮。下面是网址 -justdial.com/Kota-Rajasthan/Doctors/nct-10892680

标签: python selenium selenium-webdriver web-scraping beautifulsoup


【解决方案1】:

点击Enquire Now 按钮,诱导WebDriverWaitelement_to_be_clickable() 以及使用以下定位器。

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[contains(@class,'green-btn')][contains(.,'Enquire Now')]"))).click()

您需要导入以下代码来执行上述代码。

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

【讨论】:

  • 感谢您的回复,但是有n个按钮,class-green-btn和Text-立即查询,我认为这段代码会同时点击所有查询按钮,但我们的要求将根据列表逐一执行点击。
猜你喜欢
  • 1970-01-01
  • 2019-02-06
  • 2016-09-29
  • 2021-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-21
  • 1970-01-01
相关资源
最近更新 更多