【问题标题】:Python Selenium search for sibbling [object Text] that only have a textPython Selenium 搜索只有文本的同级 [object Text]
【发布时间】:2023-01-24 15:21:27
【问题描述】:

我想在 xpath 中获取表达式的文本,它的兄弟中只有文本 html_code

我正在尝试这种方式,但它给了我一个错误,我不知道如何选择文本,因为它没有任何标签


driver.find_element('xpath','//li[@class="icon-feature"]//i[@class="icon-stotal"]//following-sibling::text()').text

错误:

InvalidSelectorException: invalid selector: The result of the xpath expression "//li[@class="icon-feature"]//i[@class="icon-stotal"]//following-sibling::text()" is: [object Text]. It should be an element.

我只想拥有“总计 121 平方米”。

对此的任何帮助表示赞赏。

【问题讨论】:

    标签: python selenium web-scraping xpath html-parsing


    【解决方案1】:

    find_element() 返回一个 WebElement,它不能返回一个文本节点.因此你不能使用:

    //xpath_expression/text()
    

    【讨论】:

      猜你喜欢
      • 2018-01-23
      • 2020-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-18
      • 2021-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多