使用importxml / xpath难以抓取背景图片网址

时间:2018-12-11 03:00:03

标签: xpath google-sheets

我正在尝试将一些背景图片网址抓取到Google工作表中。这是容器的示例-

<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语句吗?非常感谢,谢谢。

1 个答案:

答案 0 :(得分:0)

您的方法接近了。尝试以下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('),'?')")
相关问题