没有这样的元素:无法找到元素:{“方法”:“ css选择器”,“选择器”:“。contact-button链接电话”} python中的硒

问题描述 投票:1回答:1

我正在尝试从网站获取信息,然后重用它。为此,我将硒与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”,卖家的电话号码将会出现...我想获取此信息...。

应单击的项目具有类别:

contact-button link-phone {'path':'phone','id':'dcuxh','id_raw':'195069687'} atClickTracking contact-a

不幸的是,这不是静态的,它是动态的,单击后出现此错误:

selenium.common.exceptions.NoSuchElementException:消息:没有这样的消息 元素:无法找到元素:{“ method”:“ css 选择器”,“选择器”:“。contact-button link-phone”}(会话信息: chrome = 83.0.4103.97)

[请问我该如何从该网站提取该信息...

python-3.x selenium selenium-webdriver web-crawler
1个回答
1
投票

一种方法是xpath

inputElement = driver.find_element_by_xpath("//div[@data-rel='phone']")
inputElement.click()

旁注-考虑使用WebDriverWait代替time.sleep

© www.soinside.com 2019 - 2024. All rights reserved.