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:在某些其他节点发生后的任意位置查找节点_Xpath - Fatal编程技术网

XPath:在某些其他节点发生后的任意位置查找节点

XPath:在某些其他节点发生后的任意位置查找节点,xpath,Xpath,在指定的其他节点发生后,我试图在HTML文档中的任何位置查找节点。不仅是兄弟姐妹和孩子,还有远亲。 这基本上是从某个点对HTML文档进行线性搜索,我知道这在某种程度上与xpath的层次结构性质背道而驰 我需要这两个非常相似的表,其中我想解决第二个页面 下面是一个简化的例子 <div> <div> <title>Table1</title> </div> </div> <table>

在指定的其他节点发生后,我试图在HTML文档中的任何位置查找节点。不仅是兄弟姐妹和孩子,还有远亲。 这基本上是从某个点对HTML文档进行线性搜索,我知道这在某种程度上与xpath的层次结构性质背道而驰

我需要这两个非常相似的表,其中我想解决第二个页面

下面是一个简化的例子

<div>
    <div>
        <title>Table1</title>
    </div>
</div>
<table>
    <thead>
        <tr>
            <th>Col1</th>
            <th>Col2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Val1</td>
            <td>Val2</td>
        </tr>
    </tbody>
</table>

<div>
    <div>   
        <title>Table2</title>
    </div>
</div>
<table>
    <thead>
        <tr>
            <th>Col1</th>
            <th>Col2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>OtherVal1</td>
            <td>OtherVal2</td>  (==>This is the element I want)
        </tr>
    </tbody>
</table>
但是我正在使用的真正文档有更多的
和其他标记。区分这两张表最自然的方式还是标题。 这就是为什么我想这样做:


//title[text()='Table2']/[parseWholeCodeAfterThis]/table/tbody/tr/td[2]
我猜您正在寻找以下轴:

//title[text()='Table2']/following::table//tr/td[2]
这应该允许您使用
“Table2”
文本值选择
表格
,该表格位于DOM中
标题
节点之后的某处

//title[text()='Table2']/following::table//tr/td[2]