Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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源代码: <table class="uiInfoTable profileInfoTable uiInfoTableFixed"> <tbody> <tr> <th class="label">Birthday</th> <td class="data">February 4, 1988</td> </

我有以下html源代码:

<table class="uiInfoTable profileInfoTable uiInfoTableFixed">
    <tbody>
        <tr>
            <th class="label">Birthday</th>
            <td class="data">February 4, 1988</td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <th class="label">Interested In</th>
            <td class="data">women</td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <th class="label">Gender</th>
            <td class="data">male</td>
        </tr>
    </tbody>
    //           etc....        
</table>

感谢您的帮助

我发现了三个主要问题:

  • 要比较的字符串中的换行
  • 元素名称错误(
    a
    而不是
    table
    span
    而不是其他名称)
  • 拼写错误“intrest”
无论如何,您最好选择所有具有匹配表头单元格的
元素,然后选择所有匹配的子元素。此外,您还可以省略实际调用的
text()
调用

这将有助于:

//表[@class='uiInfoTable profileInfoTable uiInfoTableFixed']//tr[
th[
@class='label'和
(.='birth'或.='interesting'或.='Relationship Status'或.='Languages')
]
]/*[local-name()='th'或local-name()='td']
这是一个XPath 1.0解决方案,也适用于较新的XPath版本。对于较新的XPath版本,您可以更改为更短的版本

//表[@class='uiInfoTable profileInfoTable uiInfoTableFixed']//tr[
th[@class='label'和
.=(‘生日’、‘感兴趣’、‘关系状态’、‘语言’)]
]/(运输署,th)
elements = driver.FindElements(By.XPath("//a[@class='uiInfoTable profileInfoTable
 uiInfoTableFixed']//span[@class='label' and (text()='Birthday' or text()='Intrested 
In' or text()='Relationship Status' or text()='Languages')]")).ToList();