Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获取XPath的Text()值_Xpath - Fatal编程技术网

如何获取XPath的Text()值

如何获取XPath的Text()值,xpath,Xpath,我试图在表中获取someValue的文本值 这是html: <div class="giveHeight"> <table width="100%" cellspacing="0" cellpadding="3" border="0" id="loads" class="dataTable" aria-describedby="loads_info"> <thead> <tr class="tableHeading" role="

我试图在表中获取someValue的文本值

这是html:

<div class="giveHeight">
<table width="100%" cellspacing="0" cellpadding="3" border="0" id="loads" class="dataTable" aria-describedby="loads_info">
    <thead>
        <tr class="tableHeading" role="row">
            ...Header...
        </tr>
    </thead>                    
    <tbody role="alert" aria-live="polite" aria-relevant="all">
        <tr class="odd">
            <td class=" ">SomeValueInTheFirtColumn</td>
            <td style="text-align: center;" class=" ">1</td>
            <td class=" ">aabbcc</td>
            <td class=" ">CityA</td>
            <td class=" ">AA</td>
            <td class=" ">CityB</td>
            <td class=" ">BB</td>
            <td style="text-align: right;" class=" ">00</td>
            <td style="text-align: right;" class=" ">$1.00</td>
            <td style="text-align: right;" class=" ">$1.00</td>
            <td style="text-align: right;" class=" ">
                <a href="/xx/xx.asp?id=99999">
                    <img src="/tab/images/icons/view.gif" border="0" alt="view" width="14" height="14">
                </a>
            </td>
            <td style="text-align: right;" class=" "></td>
        </tr>
    </tbody>
</table>

我不确定这是否是您想要的,但要在FirtColumn中获得值SomeValues,您的XPath中只多了一个td。所以把它改成

//div[@class='giveHeight']/table/tbody/tr/td[following-sibling::td[text()='CityA']/following-sibling::td[text()='CityB']]/text()
结果是在第五列中得到一些值

但以下较短的表达式确实实现了相同的结果:

//div[@class='giveHeight']/table/tbody/tr/td[1]/text()
另一方面,如果您希望检索CityA和CityB之间的值“AA”,则以下XPath将提取您想要的内容:

//div[@class='giveHeight']/table/tbody/tr/td[following-sibling::td[text()='CityB'] and preceding-sibling::td[text()='CityA']]/text()

您没有解释要查找的内容,需要指定正在使用的编程语言/库。
//div[@class='giveHeight']/table/tbody/tr/td[following-sibling::td[text()='CityB'] and preceding-sibling::td[text()='CityA']]/text()