首页 > 解决方案 > 如何在 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}]'>

标签: pythonseleniumweb-scrapingxpath

解决方案


您可以使用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并且它只有一个值,包裹在 内[],不要对此感到困惑。


推荐阅读