我可以使用 selenium 在网站上点击这个元素吗?
Can I use selenium to click this element on the website?
我正在尝试单击一个网站的元素。
来源是:
<dd data-value="33" data-text="" data-target="brand">奥迪</dd>
它应该是一个可以点击的下拉按钮,但我尝试了不同的方法:
- find_elements_by_css_selector
- find_elements_by_xpath 我刚从 google
复制过来的
但是发现selenium找到的元素是不可点击的。我很好奇我还能点击它
网站是https://www.autohome.com.cn/beijing/(您可能需要将其翻译成英文)。
.
非常感谢任何帮助。
此外,由于我将在这里点选所有汽车品牌进行抓取,希望这些方法可以推广到其他汽车,例如图中列出的阿尔法罗密欧。
非常感谢!
打开元素错误。
<div class="option option-brand">
刚刚在 Python 中展示了一个示例。
wait = WebDriverWait(driver, 10)
driver.get("https://www.autohome.com.cn/beijing/")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.option.option-brand"))).click()
name='奥迪'
wait.until(EC.element_to_be_clickable((By.XPATH,"//dd[.='{}']".format(name)))).click()
导入
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
我正在尝试单击一个网站的元素。
来源是:
<dd data-value="33" data-text="" data-target="brand">奥迪</dd>
它应该是一个可以点击的下拉按钮,但我尝试了不同的方法:
- find_elements_by_css_selector
- find_elements_by_xpath 我刚从 google 复制过来的
但是发现selenium找到的元素是不可点击的。我很好奇我还能点击它
网站是https://www.autohome.com.cn/beijing/(您可能需要将其翻译成英文)。
非常感谢任何帮助。
此外,由于我将在这里点选所有汽车品牌进行抓取,希望这些方法可以推广到其他汽车,例如图中列出的阿尔法罗密欧。
非常感谢!
打开元素错误。
<div class="option option-brand">
刚刚在 Python 中展示了一个示例。
wait = WebDriverWait(driver, 10)
driver.get("https://www.autohome.com.cn/beijing/")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.option.option-brand"))).click()
name='奥迪'
wait.until(EC.element_to_be_clickable((By.XPATH,"//dd[.='{}']".format(name)))).click()
导入
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC