【问题标题】:How to generate xpath by looking for a string in an HTML document?如何通过在 HTML 文档中查找字符串来生成 xpath?
【发布时间】:2012-05-08 07:40:31
【问题描述】:

我有一个 HTML 文档,我愿意找出包含某个字符串的元素的 xpath。

再详细一点:

我的 HTML 文档是动态创建的,我没有 s 的特定名称。我感兴趣的 div 看起来(或多或少):

<div>Country: China</div>
<div>Type: Earphones</div>

我想得到整个字符串“国家:中国”。为此,我想通过在 HTML 中搜索“Country:”来找到该 div 的 xpath。

我希望我足够具体...谢谢!

【问题讨论】:

    标签: c# html xpath


    【解决方案1】:

    这里有几种方法:

    //div[contains(child::text(), "Country:")]
    //div/child::text()[contains(., "Country:")]/parent::node()
    

    如果您想在浏览器中尝试,请尝试in-browser XPath bookmarklet

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-29
      • 2023-03-14
      • 2018-04-06
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多