xpath icon indicating copy to clipboard operation
xpath copied to clipboard

求助一下!!!

Open songguowei opened this issue 5 years ago • 1 comments

<a href="/ class="figure" style="background-image: url(./0080xEK2ly1gnbg4yvs0bj30le0u0n25.jpg);filter:'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale')';
-moz-background-size:100% 100%; background-size:100% 100%;">

怎么匹配 background-image: url

songguowei avatar Feb 04 '21 06:02 songguowei

摸索了好几个小时,终于弄好了,在这写出来希望可以帮到遇到同样问题的同学。

可以使用正则+正则捕获做到取出图片地址,我这边的 style 参数中只有一个 background-image 属性,你的有好几个属性,所以我不确定我写好的正则是否适合你的情况,下面以我的为例:

html:

<div class="post-box-image" style="background-image: url(https://tva1.sinaimg.cn/large/007Pu4zFly1h7bj8p32psj30f00m8q3p.jpg);"><span></span></div>

xpath:

//div[@class="post-box-image"]/@style

在 xpath 表达式后面加上正则表达式即可仅取出图片地址:

//div[@class="post-box-image"]/@style##.*background-image:\s*url\((.*?)\);.*##$1

正则表达式语法:

rule##replaceRegex##replacement##replaceFirst

其中 rule 可以是 xpath jsonpath css 等等,参考链接

listenerri avatar Oct 20 '22 13:10 listenerri