[XPath] XPath 与 lxml (四)XPath 运算符
2024-08-24 07:45:33
XPath 中支持的运算符
# | 或: 返回所有 price 和 title 节点集合
>>> root.xpath('//price|//title')
[<Element title at 0x2d888c8>, <Element price at 0x2d88878>, <Element title at 0x2d88940>, <Element price at 0x2d88738>] # + 加法:返回所有 price 子元素前两个之和
>>> root.xpath('//price[1]/text() + //price[2]/text()')
69.94 # - 减法:返回所有 price 子元素前两个之差
>>> root.xpath('//price[1]/text() - //price[2]/text()')
-9.960000000000004 # * 乘法:返回所有 price 子元素前两个之积
>>> root.xpath('//price[1]/text() * //price[2]/text()')
1198.1005 # div 除法:返回所有 price 子元素前两个之商
>>> root.xpath('//price[1]/text() div //price[2]/text()')
0.7506883604505631 # = 等于:返回 True 或 False
>>> root.xpath('//price[1]/text() = //price[2]/text()')
False # != 不等于:返回 True 或 False
>>> root.xpath('//price[1]/text() != //price[2]/text()')
True # < 小于:返回 True 或 False
>>> root.xpath('//price[1]/text() < //price[2]/text()')
True # <= 小于或等于:返回 True 或 False
>>> root.xpath('//price[1]/text() <= //price[2]/text()')
True # > 大于:返回 True 或 False
>>> root.xpath('//price[1]/text() > //price[2]/text()')
False # >= 大于或等于:返回 True 或 False
>>> root.xpath('//price[1]/text() >= //price[2]/text()')
False # or 或:返回 True 或 False
>>> root.xpath('//price[1]/text() > 29.9 or //price[2]/text() > 40')
True # and 与:返回 True 或 False
>>> root.xpath('//price[1]/text() > 29.9 and //price[2]/text() > 40')
False # mod 求余
>>> root.xpath('11 mod 2')
1.0
最新文章
- Hibernate框架使用案例
- CSS3动画几个平时没注意的属性
- python中字典的使用
- hdu4289 最小割最大流 (拆点最大流)
- JAVA中的定时调度(Timer和TimerTask)
- (转)Python JSON序列化
- 用JQuery中的Ajax方法获取web service等后台程序中的方法
- 同步github工程gitcafe
- Vue.js 计算属性的秘密
- 在查询语句中使用 NOLOCK 和 READPAST
- C#のsocket通信
- Anaconda 虚拟环境安装及应用
- Android开发——JobScheduler机制
- spring事务详解(一)初探讨
- [LeetCode] 733. Flood Fill_Easy tag: BFS
- 【linux基础】查看硬盘位置信息
- 本地启动activemq,报错解决
- 【BZOJ】1912: [Apio2010]patrol 巡逻(树的直径)
- HDU - 4866 主席树 二分
- XML布局之路
热门文章
- C++头文件的工作原理
- 【转】【Centos】centos 安装libtorrent/rtorrent
- 第三百七十七节,Django+Xadmin打造上线标准的在线教育平台—apps目录建立,以及数据表生成
- zend framework分析总结[转]
- struts2系列(二):struts2参数传递错误、struts2的输入错误验证
- Java如何查看线程的优先级?
- 使用Maven模板创建项目
- MVC4小细节
- 【转】在64位windows下使用instsrv.exe和srvany.exe创建windows服务
- windows上開啟多個apache服務器