python - 如何在 Xpath 中表达以下 HTML 代码行?
问题描述
代码行如下:
<input type="hidden" id="data_mentalidad_web_35084" value='[{"name":"Extensor Cable Riser PEC 300 PCI-E x16 ","id":"35084","price":"29990","brand":"Deepcool \u00ae ","category":"Tarjetas Gr\u00e1ficas","variant":"","quantity":1,"position":1}]'>
其中我只想要以粗体标记的内容:
<input type="hidden" id="data_mentalidad_web_35084" value='[{"name":"***Extensor Cable Riser PEC 300 PCI-E x16*** ","id":"35084","price":"***29990***","brand":"Deepcool \u00ae ","category":"***Tarjetas Gr\u00e1ficas***","variant":"","quantity":***1***,"position":1}]'>
解决方案
您可以使用contains
多次,and
如下所示:
//input[contains(@value,'Extensor Cable Riser PEC 300 PCI-E x16') and contains(@value,'29990') and contains(@value,'Tarjetas Gr\u00e1ficas') and contains(@value,'1')]
您还需要了解 value 是 anattribute
并且它只有一个值,包裹在 内[]
,不要对此感到困惑。
推荐阅读
- c++ - 在函数返回类型之前“定义”
- angular - 在服务中组合来自两个来源的数据的好方法是什么?
- python - Python冒号不是数字序列?
- regex - 使用正则表达式在引号内查找字符串
- kubernetes - 如何跨多个 Kubernetes 集群设置一个 Redis 集群
- vb.net - 如何从数据表中选择所有记录仅以一列不同
- javascript - 根据不同数组的 array.sort() 对一个数组进行排序
- reactjs - 如何使用 runSaga 启动 redux saga watcher
- angular - Bootstrap 没有按预期的角度加载
- javascript - 如何在 discord.js 中测试表情符号是否为动画