Xpath-如何获得内部的跨度(div / div [3] / div [1] / span)

问题描述 投票:-1回答:1

HTML:

<div id="quote-header-info" data-yaft-module="tdv2-applet-QuoteHeader" class="quote-header-section Cf Pos(r) Mb(5px) Maw($maxModuleWidth) Miw($minGridWidth) smartphone_Miw(ini) Miw(ini)!--tab768 Miw(ini)!--tab1024 Mstart(a) Mend(a) Px(20px) smartphone_Pb(0px) smartphone_Mb(0px)" data-test="quote-header" data-reactid="2">
    <div class="W(100%) Bdts(s) Bdtw(7px)  Bdtc($c-fuji-red-2-b)" data-reactid="3"></div>
    <div class="Mt(15px)" data-reactid="4"><div class="D(ib) Mt(-5px) Mend(20px) Maw(56%)--tab768 Maw(52%) Ov(h) smartphone_Maw(85%) smartphone_Mend(0px)" data-reactid="5"><div class="D(ib) " data-reactid="6"><h1 class="D(ib) Fz(18px)" data-reactid="7">Teva Pharmaceutical Industries Limited (TEVA)</h1></div><div class="C($c-fuji-grey-j) Fz(12px)" data-reactid="8"><span data-reactid="9">NYSE - NYSE Delayed Price. Currency in USD</span></div></div><div class="D(ib) Va(t) Mt(-8px) Mend(15px) smartphone_Mend(0px) smartphone_Fl(end) smartphone_Mt(0px)" data-reactid="10"><div class="qsp-watchlist-add Td(u):h" data-reactid="11"><div class="Pos(r) D(ib) O(n):f Cur(p)" tabindex="0" data-reactid="12"><div class="addButton Cur(p) Pstart(13px) Pend(16px) Pt(5px) Pb(7px) Mt(8px) Fz(12px) Fw(500) C($company360Grey) Bd Bdc($c-fuji-blue-1-b) Bdrs(15px) Bgc($c-fuji-blue-1-b):h C(white):h" data-reactid="13"><svg class="Mend(5px) addButton:h_Stk(white)! addButton:h_Fill(white)! Cur(p)" width="16" style="fill:#0081f2;stroke:#0081f2;stroke-width:0;vertical-align:bottom;" height="16" viewBox="0 0 24 24" data-icon="star" data-reactid="14"><path d="M8.485 7.83l-6.515.21c-.887.028-1.3 1.117-.66 1.732l4.99 4.78-1.414 6.124c-.2 1.14.767 1.49 1.262 1.254l5.87-3.22 5.788 3.22c.48.228 1.464-.097 1.26-1.254l-1.33-6.124 4.962-4.78c.642-.615.228-1.704-.658-1.732l-6.486-.21-2.618-6.22c-.347-.815-1.496-.813-1.84.003L8.486 7.83zm7.06 6.05l1.11 5.11-4.63-2.576L7.33 18.99l1.177-5.103-4.088-3.91 5.41-.18 2.19-5.216 2.19 5.216 5.395.18-4.06 3.903z" data-reactid="15"></path></svg><span class="D(n)--tab768 Mend(1px) Va(tb)" data-reactid="16"><span data-reactid="17">Add to watchlist</span></span></div><!-- react-text: 18 --><!-- /react-text --></div></div></div><div class="D(ib) Fl(end) W(300px) Cl(end)--mobxl W(250px)--tab768" data-reactid="19"><div class="Pos(r) D(ib) Mend(10px) Va(m) W(100%)" data-test="add-symbol-overlay" data-yaft-module="tdv2-applet-SymbolLookup" data-reactid="20"><div class="clear-button-inside Pos(r) react-autocomplete-box" data-reactid="21"><div class="Cf" data-reactid="22"><fieldset class="Pos(r) D(ib) W(100%)" data-reactid="23"><input type="text" class=" Bdrs(0) Bxsh(n)! Fz(s) Bxz(bb) D(ib) Bg(n) Pend(5px) Px(8px) Py(0) H(30px) Lh(30px) Bd O(n):f O(n):h Bdc($c-fuji-grey-c) Bdc($c-fuji-blue-1-b):f Bdc($c-fuji-punch-a):inv C($dataRed):in M(0) Pstart(10px) Bxz(bb) Bgc(white) W(100%) H(32px)! Lh(32px)!" name="s" tabindex="1" aria-label="Quote Lookup" placeholder="Quote Lookup" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-reactid="24"></fieldset><button class=" Bdrs(2px) Td(n) Fz(s) D(ib) Bxz(bb) Py(0) Px(10px) H(30px) Lh(30px) Bd  Bgc($c-fuji-blue-1-b) Bgc($actionBlueHover):h C(white) C(#aaa):di Bdc($c-fuji-blue-1-b) Bdc($c-fuji-grey-c):di Bg($c-fuji-grey-c):di H(32px)! Lh(n)! Va(m) Pos(a) Fl(end) End(1px)" type="submit" data-reactid="25"><svg class="Fill(white)! Stroke(white)! Cur(p)" width="20" style="fill:#fff;stroke:#fff;stroke-width:0;vertical-align:bottom;" height="20" viewBox="0 0 24 24" data-icon="search" data-reactid="26"><path d="M9 3C5.686 3 3 5.686 3 9c0 3.313 2.686 6 6 6s6-2.687 6-6c0-3.314-2.686-6-6-6m13.713 19.713c-.387.388-1.016.388-1.404 0l-7.404-7.404C12.55 16.364 10.85 17 9 17c-4.418 0-8-3.582-8-8 0-4.42 3.582-8 8-8s8 3.58 8 8c0 1.85-.634 3.55-1.69 4.905l7.403 7.404c.39.386.39 1.015 0 1.403" data-reactid="27"></path></svg></button></div><!-- react-text: 28 --><!-- /react-text --></div><svg class="D(n) Cur(p)" width="24" style="fill:#000;stroke:#000;stroke-width:0;vertical-align:bottom;" height="24" viewBox="0 0 24 24" data-icon="search" data-reactid="29"><path d="M9 3C5.686 3 3 5.686 3 9c0 3.313 2.686 6 6 6s6-2.687 6-6c0-3.314-2.686-6-6-6m13.713 19.713c-.387.388-1.016.388-1.404 0l-7.404-7.404C12.55 16.364 10.85 17 9 17c-4.418 0-8-3.582-8-8 0-4.42 3.582-8 8-8s8 3.58 8 8c0 1.85-.634 3.55-1.69 4.905l7.403 7.404c.39.386.39 1.015 0 1.403" data-reactid="30"></path></svg></div></div></div>
    <div class="My(6px) Pos(r) smartphone_Mt(6px)" data-reactid="31">
            <div class="D(ib) Va(m) Maw(65%) Maw(60%)--tab768 Ov(h)" data-reactid="32">
                <div class="D(ib) Mend(20px)" c="33">
                    <span class="Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)" data-reactid="34">6.97</span>
                    <span class="Trsdu(0.3s) Fw(500) Pstart(10px) Fz(24px) C($dataRed)" data-reactid="35">-0.07 (-0.99%)</span>

我想在第一跨度内获取-6.97。我怎么得到这个?

html xpath
1个回答
0
投票

这里是css和xpath。

CSS

#quote-header-info span[class*='Trsdu']:nth-of-type(1)

enter image description here

xPath:

//div[@id='quote-header-info']//span[contains(@class,'Trsdu')][1]

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.