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

最新文章

  1. Hibernate框架使用案例
  2. CSS3动画几个平时没注意的属性
  3. python中字典的使用
  4. hdu4289 最小割最大流 (拆点最大流)
  5. JAVA中的定时调度(Timer和TimerTask)
  6. (转)Python JSON序列化
  7. 用JQuery中的Ajax方法获取web service等后台程序中的方法
  8. 同步github工程gitcafe
  9. Vue.js 计算属性的秘密
  10. 在查询语句中使用 NOLOCK 和 READPAST
  11. C#のsocket通信
  12. Anaconda 虚拟环境安装及应用
  13. Android开发——JobScheduler机制
  14. spring事务详解(一)初探讨
  15. [LeetCode] 733. Flood Fill_Easy tag: BFS
  16. 【linux基础】查看硬盘位置信息
  17. 本地启动activemq,报错解决
  18. 【BZOJ】1912: [Apio2010]patrol 巡逻(树的直径)
  19. HDU - 4866 主席树 二分
  20. XML布局之路

热门文章

  1. C++头文件的工作原理
  2. 【转】【Centos】centos 安装libtorrent/rtorrent
  3. 第三百七十七节,Django+Xadmin打造上线标准的在线教育平台—apps目录建立,以及数据表生成
  4. zend framework分析总结[转]
  5. struts2系列(二):struts2参数传递错误、struts2的输入错误验证
  6. Java如何查看线程的优先级?
  7. 使用Maven模板创建项目
  8. MVC4小细节
  9. 【转】在64位windows下使用instsrv.exe和srvany.exe创建windows服务
  10. windows上開啟多個apache服務器