如何获得没有价值的td?

问题描述 投票:0回答:3

我有一个表,其中有时有些记录没有值

我正在使用这些Xpath

//table/tbody/tr/td[not(td[string-length(normalize-space(text()))=0])]

//td[not(td[string-length(normalize-space(text()))=0])]

但是它选择了整个表格,我怎样才能只选择空的td?

感谢您的帮助:)

xpath
3个回答
1
投票

让事情变得简单。如果您想选择不带文字的

td
,请尝试:

//table/tbody/tr/td[not(text())]

演示


0
投票

要完成此操作,有两种选择空

td
元素的替代方法(第一个方法删除 XPath 表达式中无用的部分(谓词内的
normalize-space()
text()
td[]
):

//td[string-length()=0]
//td[.=""]

第一个 XPath 将查找内容长度等于 0 的 td 元素。 第二个 XPath 将查找不包含任何内容的 td 元素。

但是关于您的 XPath 试用,您似乎想要选择非空的

td
元素。如果是这种情况,只需在谓词内添加
not
:

//td[not(string-length()=0)]
//td[not(.="")] 

0
投票

//td[not(字符串长度(标准化空间(text()))=0)]

用这个,这个有效 你的语法错误

© www.soinside.com 2019 - 2024. All rights reserved.