基于标签的表单元格(td)内容的XPath?

时间:2018-09-11 01:40:59

标签: html xml xpath

任何人都可以帮助我找到合适的XPath来从此网页中检索Average WinLoss value(36.68点和-38.56点):

https://www.myfxbook.com/members/babatrader/ic-markets-live/2595252

这是HTML的一部分

<table class="maxWidth" cellspacing="0" id="trades">
<tbody><tr>
<td valign="top">
    <table cellspacing="0" class="advanced border0L">
        <tbody><tr class="bg1">
            <td>Trades:</td>
            <td class="alignR">2885</td>
        </tr>



                                <tr>
            <td>Profitability:</td>
            <td align="right" class="pointer">
                        <span id="wonTip" class="Won 1619 out of 2885 trades, which represents 56%.<br/>Lost 1266 out of 2885 trades, which represents 44%."><div class="blockHolder">
                            <div class="greenBlock floatLeft" style="width:56px"></div>
                            <div class="redBlock floatLeft" style="width:44px"></div>
                        </div></span>
            </td>
        </tr>

        <tr class="bg1">
            <td>Pips:</td>
            <td class="alignR">10571.7</td>
        </tr>

        <tr>
            <td>Average Win:</td>
            <td class="alignR">36.68 pips / €3.31</td>
        </tr>
        <tr class="bg1">
            <td>Average Loss:</td>
            <td class="alignR">-38.56 pips / -€3.56</td>
        </tr>
        <tr>

            <td>    Lots:</td>
            <td class="alignR">38.94</td>
        </tr>
        <tr class="bg1">
            <td>Commissions:</td>
            <td class="alignR">-€226.56</td>
        </tr>


                                    </tbody></table>
        </td>
        <td valign="top">
            <table cellspacing="0" class="advanced border0R border0L">
                <tbody><tr>
                    <td>Longs Won:</td>
                    <td align="right">
                        <span class="gray">(687/1247) </span> 55%
                        </td>
                </tr>
                <tr class="bg1">
                    <td>Shorts Won:</td>
                    <td align="right">
                        <span class="gray">(932/1638) </span> 56%
                        </td>
                </tr>


                <tr>
                    <td>Best Trade(€):</td>
                    <td class="alignR">                             <span class="gray">(Jul 20)</span> 17.93
                    </td>
                </tr>
                <tr class="bg1">
                    <td> Worst Trade(€):</td>
                    <td class="alignR">                            <span class="gray">(Jul 19)</span> -32.08
                    </td>
                </tr>
                <tr>
                    <td>Best Trade (Pips):</td>
                    <td class="alignR">                            <span class="gray">(Sep 07)</span> 177.5
                    </td>
                </tr>
                <tr class="bg1">
                    <td>Worst Trade (Pips):</td>
                    <td class="alignR">                            <span class="gray">(Sep 06)</span> -190.0
                    </td>
                </tr>

                <tr>
                    <td>Avg. Trade Length:</td>
                    <td class="alignR">
                        22h 45m
                    </td>
                </tr>

                                    </tbody></table>
        </td>
        <td>
            <table cellspacing="0" class="advanced border0R">
                <tbody><tr class="bg1">
                    <td><span class="dotted" id="pfTip">Profit Factor:</span></td>
                    <td class="alignR">
                                                                                 1.19
                                                                         </td>
                </tr>
                <tr>
                    <td><span class="dotted" id="sdTip">Standard Deviation:</span></td>
                    <td class="alignR">€4.30</td>
                </tr>
                                                        <tr class="bg1">
                                                            <td><span class="dotted" id="sharpTip">Sharpe Ratio:</span></td>
                                             <td class="alignR">
                                                 0.00
                                             </td>
                                        </tr>


                <tr>
                    <td><span class="dotted" id="zTip">Z-Score (Probability):</span></td>
                    <td class="alignR">
                        -31.21 (99.99%)
                    </td>
                </tr>

                <tr class="bg1">
                    <td><span class="dotted" id="expTip">Expectancy:</span></td>
                    <td class="alignR">3.7 Pips / €0.30</td>
                </tr>
                                                        <tr>
                                                            <td><span class="dotted" id="ahprTip">AHPR:</span></td>
                                            <td class="alignR">0.01%</td>
                                        </tr>
                 <tr class="bg1">
                                                            <td><span class="dotted" id="ghprTip">GHPR:</span></td>
                                            <td class="alignR">0.01%</td>
                                        </tr>

                                    </tbody></table>
        </td>
    </tr>

</tbody></table>

我尝试过没有成功:以下是我尝试过的一个。

    //*[@id="trades"]/tbody/tr/td[1]/table/tbody/tr[5]/td[2]

    //*[@id="trades"]/tr/td[1]/table/tbody/tr[5]/td[2]

和许多其他..;-)

2 个答案:

答案 0 :(得分:0)

我必须删除两个“ tbody”

// * [@ id ='trades'] / tr / td / table / tr [4] / td [2]

答案 1 :(得分:0)

此XPath,

substring-before(//table[@id="trades"]
                 //td[.="Average Win:"]/following-sibling::td[1], " /")

将选择

36.68 pips

根据要求,您会发现它比许多替代产品都更坚固。例如,表结构可能会发生重大变化,只要两个表单元的标签和相对位置保持不变,该XPath就会继续起作用。