【问题标题】:No such element: Unable to locate element: {"method":"css selector","selector":".contact-button link-phone"} selenium in python没有这样的元素:无法找到元素:{“method”:“css selector”,“selector”:“.contact-button link-phone”} selenium in python
【发布时间】:2020-09-30 04:07:24
【问题描述】:

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

应点击的项目具有类:

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

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

selenium.common.exceptions.NoSuchElementException:消息:没有这样的 元素:无法找到元素:{“方法”:“css selector","selector":".contact-button link-phone"} (会话信息: 铬=83.0.4103.97)

请问我怎样才能从那个网站提取这些信息...

【问题讨论】:

    标签: python-3.x selenium selenium-webdriver web-crawler


    【解决方案1】:

    一种方法是使用xpath

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

    附注 - 考虑使用 WebDriverWait 而不是 time.sleep

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-18
      • 1970-01-01
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多