【发布时间】:2014-07-30 07:23:50
【问题描述】:
我正在使用 Xpath 根据网页中的文本选择一个元素,只要文本选择器不包含空格,它就可以工作。
When the selector does contain spaces, however, it fails.
我看过:Locating the node by value containing whitespaces using XPath
和xpath expression to remove whitespace
和how to get the normalize-space() xpath function to work?
但这没有用。
失败的 html 示例:
<tr style="vertical-align:top;">
<td style="height:15px;"></td>
<td class="cs9D60B82">Yellow Fees</td>
<td class="cs9D60B82">Group1</td>
<td class="cs9D60B82">Yes</td>
<td class="cs9DB0B82"></td>
<td class="cs9D60B82">QD 1,234.56</td>
</tr>
这些工作,但也可以返回以相同文本开头的其他节点:
"//td[starts-with( normalize-space(), 'Yellow')]"
"//td[starts-with(text(), 'Yellow')]"
这些不起作用:
"//td[normalize-space(.) = 'Yellow Fees']"
"//td[translate(text(), '	

','') = 'YellowFees']"
"//td[translate(text(), ' 	

','') = 'Yellow Fees']"
"//td[translate(text(), ' ','') = 'YellowFees']"
"//td[translate(text(), '	

','') = 'Yellow Fees']"
"//td[matches( text(), 'Yellow Fees')]"
【问题讨论】: