使用importxml/xpath获取背景图像url时出现问题



我正在尝试将一些背景图像URL刮到谷歌工作表中。这是一个集装箱的例子

<div class="_rs9 _1xcn">
<div class="_1ue-">
<section class="_4gsw _7of _1ue_" style="background-image: url(https://scontent.x.com/v/t64.5771-25/38974906_464042117451453_1752137156853235712_n.png?_nc_cat=100&amp;_nc_ht=scontent.x.com&amp;oh=c19f15536205be2e1eedb7f7fc7cb61b&amp;oe=5C4442FD)">
<div class="_7p2">
</div>
</section>

我需要从https到png之后的问号。我知道有一种方法可以在前/后使用子字符串,但我遇到了困难,尤其是转义引号。

这是我的尝试。这只会给我一个"#N/A":

=IMPORTXML(B2,"substring-before(substring-after(//section[@class='_4gsw _7of _1ue_']/@style, """"background-image: url(""""), """")"""")")

有人能帮我完成完整的importxml语句吗?非常感谢,谢谢。

您的方法很接近。尝试以下XPath表达式:

substring-before(substring-after(//section[@class='_4gsw _7of _1ue_']/@style, 'background-image: url('),'?')

整个表达式可能是这样的:

=IMPORTXML(B2,"substring-before(substring-after(//section[@class='_4gsw _7of _1ue_']/@style, 'background-image: url('),'?')")

最新更新