如何在 Xpath 中将"not"属性与"class name"一起使用?


//span[@class='cname']//text()[not(parent::em[@class='multiple']) and not(normalize-space()='')]

我需要删除此代码中的text()。因为当我使用text()时,它就变成了一个对象。但是如果我键入";CCD_ 3";在我的python代码的末尾,它转到元素。

我需要一个元素而不是一个对象。所以我需要重写";CCD_ 4";在没有任何其他更改的情况下从代码中删除,或者将其从对象更改为元素。

如果要选择该text()的父元素,可以将/../parent::*添加到XPath 的末尾

//span[@class='cname']//text()[not(parent::em[@class='multiple']) and not(normalize-space()='')]/..

//span[@class='cname']//text()[not(parent::em[@class='multiple']) and not(normalize-space()='')]/parent::*

相关内容

最新更新