没有这样的元素:无法找到元素:{"method":"css selector","selector":".contact-button link-phone"} [= 中的硒13=]
No such element: Unable to locate element: {"method":"css selector","selector":".contact-button link-phone"} selenium in python
我正在尝试从网站获取信息,然后重新使用它...为此,我将 selenium 与 python 结合使用。
到目前为止我所做的是:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.olx.ro/oferta/vand-apartament-3-camere-2-dormitor-1-living-IDdJOij.html')
time.sleep(10)
inputElement = driver.find_element_by_class_name("spoiler")
time.sleep(12)
inputElement.send_keys(Keys.ENTER)
如果您在此页面上单击 "suna vanzatorul",将显示卖家的 phone 号码...我想获取此信息....
应该点击的项目有 class:
联系按钮 link-phone {'path': 'phone', 'id': 'dcuxh', 'id_raw': '195069687'} atClickTracking contact-a
不幸的是,这不是静态的,它是动态的,点击后出现此错误:
selenium.common.exceptions.NoSuchElementException: Message: no such
element: Unable to locate element: {"method":"css
selector","selector":".contact-button link-phone"} (Session info:
chrome=83.0.4103.97)
请问我如何从该网站提取该信息...
一种方法是 xpath
:
inputElement = driver.find_element_by_xpath("//div[@data-rel='phone']")
inputElement.click()
旁注 - 考虑使用 WebDriverWait
而不是 time.sleep
。
我正在尝试从网站获取信息,然后重新使用它...为此,我将 selenium 与 python 结合使用。
到目前为止我所做的是:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.olx.ro/oferta/vand-apartament-3-camere-2-dormitor-1-living-IDdJOij.html')
time.sleep(10)
inputElement = driver.find_element_by_class_name("spoiler")
time.sleep(12)
inputElement.send_keys(Keys.ENTER)
如果您在此页面上单击 "suna vanzatorul",将显示卖家的 phone 号码...我想获取此信息....
应该点击的项目有 class:
联系按钮 link-phone {'path': 'phone', 'id': 'dcuxh', 'id_raw': '195069687'} atClickTracking contact-a
不幸的是,这不是静态的,它是动态的,点击后出现此错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".contact-button link-phone"} (Session info: chrome=83.0.4103.97)
请问我如何从该网站提取该信息...
一种方法是 xpath
:
inputElement = driver.find_element_by_xpath("//div[@data-rel='phone']")
inputElement.click()
旁注 - 考虑使用 WebDriverWait
而不是 time.sleep
。