python - 如何在 Xpath 中使用带有“类名”的“not”属性?
问题描述
//span[@class='cname']//text()[not(parent::em[@class='multiple']) and not(normalize-space()='')]
我需要text()
在这段代码中删除。因为当我使用它时text()
,它就变成了一个对象。.text
但是,如果我在我的 python 代码末尾键入“ ”,它就会变成 element。
我需要一个元素而不是一个对象。所以我需要text()
从代码中重写“”而不进行任何其他更改,或者将其从对象更改为元素。
解决方案
如果您想选择它的父元素,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::*
推荐阅读
- javascript - 花括号内的 JSX
- algorithm - 将线条绘制转换为多边形的算法
- r - 将 geom_text 从不同的数据框标签分配给图形
- javascript - PDF 流适用于 Chrome,但不适用于 IE11
- azure - 如果不与 AAD 集成,AKS 群集是否默认不安全?
- android - 如何在 Android Studio IDE 中查看变量的类型
- c# - 合并来自多个控制器的 HttpGet 方法
- git - 如何更改 github repo 的顶级目录
- python - 如何使用python将两个数据csv合并到一个文件中
- python - 拼接具有元数据完整性的热图像