【问题标题】:Can't find span text in selenium python在 selenium python 中找不到跨度文本
【发布时间】:2021-10-10 13:55:00
【问题描述】:

在此处输入代码我正在对电影页面进行网络抓取,但它没有找到跨度,尽管在 xpath 中它很好并且可以识别它,它没有找到文本,当我打印它时,它打印为空。

这是代码 enter image description here

找到物品的证据 enter image description here

网址

https://www.cinecolombia.com/cali/peliculas/el-olvido-que-seremos 路径

//section@class="collapsible show-times-collapse"//div@class="show-times-group"//div[@class="show-times-group__attrs"]/span1

最后的元素是带括号的,我不认识它的堆栈跨度

xpath enter image description here

还可以尝试在答案中向我推荐的内容,但它也不起作用 enter image description here

【问题讨论】:

    标签: python-3.x selenium selenium-webdriver web-scraping selenium-chromedriver


    【解决方案1】:

    试试这个 XPath:

    (//div[@class='show-times-group__attrs']/span)[1]
    

    UPD
    该元素最初隐藏在可折叠元素内。
    因此,要使用 Selenium 查看它,您首先必须打开它。
    获取文本的代码将是:

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    wait = WebDriverWait(driver, 20)
    
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.show-times-collapse__header"))).click()
    
    your_text = wait.until(EC.visibility_of_element_located((By.XPATH, "(//div[@class='show-times-group__attrs']/span)[1]"))).text
    

    【讨论】:

    • 还是不取span的文本
    • 你使用什么命令?也许您错过了之前的延迟?
    • 我如何在单元格 3 中的 jupyter 中运行它会打开浏览器并让它保持打开状态,这样我仍然可以在浏览器打开的情况下进行测试。
    • 你能告诉我你是如何从代码中获取文本的吗?
    猜你喜欢
    • 1970-01-01
    • 2019-03-23
    • 2022-12-29
    • 2020-04-29
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 2020-02-13
    相关资源
    最近更新 更多