gpt4 book ai didi

html - 使用 XPATH 定位嵌套的 HTML 数据属性

转载 作者:行者123 更新时间:2023-11-28 15:12:05 29 4
gpt4 key购买 nike

我正在努力使用 XPATH 定位某些特定的 HTML...

使用 CSS,我知道正确的定位是:

html > body > div.page-content > div.container > div.myaccount > div > div:nth-child(4) > ul > [data-coin="BTC"] > div > div:nth-child(2)

The HTML is:

<html lang="en">
<body style="">
<div class="page-content">
<div class="container" style="padding-top:10px;padding-bottom:50px">
<div class="myaccount">
<div class="row">
<div class="col-md-12">
<ul class="listgroup">
<li class="hidden-xs hidden-sm list-group-item tradeitem" data-coin="BTC" data-coindisplay="BTC">
<div class="row marketrow">
<div class="col-sm-2"><img src="/public/img/coinmd/bitcoin.png?v=68" style="height:37px"> &nbsp;Bitcoin</div>
<div class="col-sm-2">$23329.28</div>
<div class="col-sm-2">$23329.28</div>
<div class="col-sm-2">$370,105,221,964</div>
<div class="col-sm-1"><span class="moveup">14.76%</span></div>
<div class="col-sm-3">
<a href="/buy/btc" class="btn btn-default btn-sm">Buy BTC</a>&nbsp;&nbsp;
<a href="/sell/btc" class="btn btn-default btn-sm">Sell BTC</a>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

我试过的 XPATH 是:

//*[contains(concat( " ", @class, " " ), concat( " ", "col-sm-2", " " ))]

^ this works but is too generic, as the HTML element positioning will change everyday. It also doesn't take into account the data attribute of the grandparent HTML.

So my question is what is the XPATH that I need, to specifically target the this element (like I can with CSS)?

<div class="col-sm-2">$23329.28</div>

最佳答案

感谢那些为这篇文章做出贡献的人。我发现的答案是:
//*[@data-coin='BTC']/div/div[2])[1]

关于html - 使用 XPATH 定位嵌套的 HTML 数据属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48132973/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com