如何在节点中获取特定的xpath?

时间:2016-01-07 13:52:16

标签: xpath

知道如何从这里获取/includes/images/large/BW93942/hermes-swift-retourne-kelly-32-indigo-1.jpg吗?

/<img class="cloudzoom-gallery img-responsive cloudzoom-gallery-active" src="/includes/images/thumb/BW93942/xhermes-swift-retourne-kelly-32-indigo-1.jpg.pagespeed.ic.PQKVquZdzC.webp" data-cloudzoom="useZoom: '.cloudzoom', image: '/includes/images/BW93942/hermes-swift-retourne-kelly-32-indigo-1.jpg', zoomImage: '*/includes/images/large/BW93942/hermes-swift-retourne-kelly-32-indigo-1.jpg*' " pagespeed_url_hash="271624911" onload="pagespeed.CriticalImages.checkImageForCriticality(this);">

2 个答案:

答案 0 :(得分:0)

尝试下面

//img/@src

OR

//img[@class='cloudzoom-gallery img-responsive cloudzoom-gallery-active']/@src

希望它会对你有所帮助:)。

答案 1 :(得分:0)

您可以使用XPath字符串函数substring-before来获取@src之前的.pagespeed属性部分。应用您发布的HTML时,XPath

substring-before(//img[@class="cloudzoom-gallery img-responsive cloudzoom-gallery-active"]/@src, ".pagespeed")

产量

/includes/images/thumb/BW93942/xhermes-swift-retourne-kelly-32-indigo-1.jpg