-1

好的,所以我有一个使用以下源代码的脚本

<h4>
<label id="ct0_l00_PageContainer_MyContainer_sym" for="symbol">
%
</label>59</h4>

my xpath code is 
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$value = $xpath->query('//label[@id="ct0_l00_PageContainer_MyContainer_sym"]/following-sibling::text()')->item(0)->nodeValue;

这个查询工作得很好,但是在改变了一些位之后它不再工作我有了新的源代码,它在下面

<div id="ctl0_PageContainer_Container_divSummary">
                <div class="blueheaderbar">
                    <h2>
                        Summary</h2>
                </div>
                <div class="usesummary">
                    <div class="ccbody">
                        <ul>
                            <li class="greybox">
                                <div class="boxOutlineW">
                                    <span class="topLeft bg">
                                        <!--for IE6-->
                                    </span><span class="topRight bg">
                                        <!--for IE6-->
                                    </span><span class="bottomLeft bg">
                                        <!--for IE6-->
                                    </span><span class="bottomRight bg">
                                        <!--for IE6-->
                                    </span>
                                    <div class="content">
                                        <div class="pointbox">
                                            <h3>
                                                last 2 years</h3>
                                            <div class="boxOutlineG infoBoxwhite">
                                                <span class="topLeft bg">
                                                    <!--for IE6-->
                                                </span><span class="topRight bg">
                                                    <!--for IE6-->
                                                </span><span class="bottomLeft bg">
                                                    <!--for IE6-->
                                                </span><span class="bottomRight bg">
                                                    <!--for IE6-->
                                                </span>
                                                <div class="content">
                                                    <h4>
                                                        98%</h4>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            <li class="greybox">
                                <div class="boxOutlineW">
                                    <span class="topLeft bg">
                                        <!--for IE6-->
                                    </span><span class="topRight bg">
                                        <!--for IE6-->
                                    </span><span class="bottomLeft bg">
                                        <!--for IE6-->
                                    </span><span class="bottomRight bg">
                                        <!--for IE6-->
                                    </span>
                                    <div class="content">
                                        <div class="pointsbox">
                                            <h3>
                                                You have used</h3>
                                            <div class="boxOutlineG infoBoxwhite">
                                                <span class="topLeft bg">
                                                    <!--for IE6-->
                                                </span><span class="topRight bg">
                                                    <!--for IE6-->
                                                </span><span class="bottomLeft bg">
                                                    <!--for IE6-->
                                                </span><span class="bottomRight bg">
                                                    <!--for IE6-->
                                                </span>
                                                <div class="content">
                                                    <h4>
                                                        91%</h4>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            <li class="greybox">
                                <div class="boxOutlineW">
                                    <span class="topLeft bg">
                                        <!--for IE6-->
                                    </span><span class="topRight bg">
                                        <!--for IE6-->
                                    </span><span class="bottomLeft bg">
                                        <!--for IE6-->
                                    </span><span class="bottomRight bg">
                                        <!--for IE6-->
                                    </span>
                                    <div class="content">
                                        <div class="pointsbox">
                                            <h3>
                                                You still have </h3>
                                            <div class="boxOutlineG infoBoxwhite">
                                                <span class="topLeft bg">
                                                    <!--for IE6-->
                                                </span><span class="topRight bg">
                                                    <!--for IE6-->
                                                </span><span class="bottomLeft bg">
                                                    <!--for IE6-->
                                                </span><span class="bottomRight bg">
                                                    <!--for IE6-->
                                                </span>
                                                <div class="content">
                                                    <h4>
                                                        7%</h4>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

如果有人可以帮助我,我需要为这部分源代码编写一个 xpath

                                            You still have </h3>
                                            <div class="boxOutlineG infoBoxwhite">
                                                <span class="topLeft bg">
                                                    <!--for IE6-->
                                                </span><span class="topRight bg">
                                                    <!--for IE6-->
                                                </span><span class="bottomLeft bg">
                                                    <!--for IE6-->
                                                </span><span class="bottomRight bg">
                                                    <!--for IE6-->
                                                </span>
                                                <div class="content">
                                                    <h4>
                                                        7%</h4>

任何人都可以帮我改变这个,让它得到正确的 7% 的值

4

1 回答 1

0

我建议你定位li哪些内容以“你还有”开头,然后选择h4元素

这翻译成这个表达式

.//li[@class="greybox"][starts-with(normalize-space(.//h3), "You still have")]//h4

您还可以删除\n尾随

normalize-space(
    .//li[@class="greybox"][starts-with(normalize-space(.//h3), "You still have")]//h4
)
于 2013-09-02T09:19:16.973 回答