我有一个表,其中有时有些记录没有值
我正在使用这些Xpath
//table/tbody/tr/td[not(td[string-length(normalize-space(text()))=0])]
//td[not(td[string-length(normalize-space(text()))=0])]
但是它选择了整个表格,我怎样才能只选择空的td?
感谢您的帮助:)
要完成此操作,有两种选择空
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(.="")]
//td[not(字符串长度(标准化空间(text()))=0)]
用这个,这个有效 你的语法错误