【问题标题】:Python - Selenium returning empty results w/ all methodsPython - Selenium 使用所有方法返回空结果
【发布时间】:2018-04-19 20:44:18
【问题描述】:

以前有人问过这个问题,但似乎没有一个能解决我的问题。

我尝试在 this page 中定位一个元素,但我的尝试失败了:

driver = webdriver.Chrome()
driver.set_window_size(0, 0)
driver.set_window_position(0, 0)
url = "https://www.autotrader.com/cars-for-sale/2003/Aston+Martin/DB7"
driver.get(url)
print (driver.find_element_by_xpath("//span[@data-qaid='txt-lowest-price']").text)
driver.close()  

我也无法从该页面中抓取任何其他数据(by_id、by_name、by_class_name、by_css_selector),所有数据都返回空文本。

欢迎和非常感谢任何建议或反馈。

谢谢!

【问题讨论】:

    标签: python django selenium


    【解决方案1】:

    尝试替换:

    driver.find_element_by_xpath("//span[@data-qaid='txt-lowest-price']").text
    

    与:

    driver.find_element_by_xpath("//span[@data-qaid='txt-lowest-price']").get_attribute('textContent')
    

    【讨论】:

      猜你喜欢
      • 2019-01-20
      • 2021-03-06
      • 2019-03-03
      • 1970-01-01
      • 2013-07-05
      • 2023-01-17
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多