【问题标题】:Chrome Console get values from xpath arrayChrome 控制台从 xpath 数组中获取值
【发布时间】:2015-06-01 20:17:24
【问题描述】:

我正在使用 Google Chrome 控制台获取所有具有 attrValue 类的元素的数组。这是我正在使用的:

$x('//*[@class="attrValue"]');

这是我的输出:

<td class="attrValue">Transway 1A</td>, <td class="attrValue">Northbound/Westbound</td>, <td class="attrValue">Facing West</td>

获取所有元素的数组非常有用,但我正在尝试获取这些元素中的值数组。任何帮助将不胜感激。

【问题讨论】:

    标签: html google-chrome xpath google-chrome-devtools


    【解决方案1】:

    获取text()

    $x('//*[@class="attrValue"]/text()');
    

    【讨论】:

    • 太棒了!现在在元素数组中,我还有几个嵌套元素,例如 &lt;td class="attrValue"&gt;&lt;span class="esriNumericValue"&gt;110004&lt;/span&gt;&lt;/td&gt;。我怎样才能将该值包含到数组中?谢谢。
    • @user1819087 如果数组中的所有元素都包含span,那么它就是//*[@class="attrValue"]/span/text()
    • @user1819087 //*[@class="attrValue"]//text() 也可以应用于您的情况。
    • 只有少数人在里面有span
    猜你喜欢
    • 2020-08-21
    • 1970-01-01
    • 2013-08-18
    • 2017-12-07
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 2012-05-17
    相关资源
    最近更新 更多