如何在Google表格中使用IMPORTXML和Xpath来获取 URL?

问题描述 投票:0回答:1

长期读者,第一次张贴。

[尝试使用Google表格IMPORTXML功能从网页中获取图像的URL或URL片段。我相当确定我的Xpath正确,但是我什么也没得到,或者“无法解析数据”-但是,我在这里看到了其他一些人以这种方式在Google表格中获取网址的示例,不同的情况,似乎在这里都不适用。

尝试从this page中抢夺-这是相关的HTML:

        <div class="bx-wrapper" style="max-width: 100%;"><div class="bx-viewport" style="width: 100%; overflow: hidden; position: relative; height: 540px;"><ul class="A_ProductImgSlider" style="width: auto; position: relative;">
         <li class="A_ItemList" style="float: none; list-style: none; position: absolute; width: 540px; z-index: 50; display: block;">
          <div class="image A_ItemImg A_SquareOuter">
           <img src="/ec/img/D3-64I011012_M_s.jpg" onerror="this.src='/ec/images/common/NoImage.gif'" alt="main product image" id="mainImage" class="A_ItemProductImg A_Square">
          </div>
         </li>
         <li class="A_ItemList" style="float: none; list-style: none; position: absolute; width: 540px; z-index: 0; display: none;"><div class="image A_ItemImg A_SquareOuter"><img src="/ec/img/D3-64I011012_S_1m.jpg" alt="product image 1" class="A_ItemProductImg A_Square"></div></li>
         <li class="A_ItemList" style="float: none; list-style: none; position: absolute; width: 540px; z-index: 0; display: none;"><div class="image A_ItemImg A_SquareOuter"><img src="/ec/img/D3-64I011012_S_2m.jpg" alt="product image 2" class="A_ItemProductImg 

我进行了以下查询,以尝试使用后续的HTML:

=IMPORTXML(A2,"//*[@id='product_image']/div[1]/div[1]/ul/li[1]/div/img src")

具有相关URL的A2。

我认为Xpath在这里是正确的,但不确定为什么它不能给我我想要的结果。我玩了一点,但是没有运气。

非常感谢您抽出宝贵的时间阅读并提供帮助。

html xml xpath google-sheets google-sheets-importxml
1个回答
0
投票

这个答案怎么样?请认为这只是几个答案之一。

示例公式:

在这种情况下,https://www.mikigakki.com/ec/pro/disp/H/D3-64I011012?sFlg=2放在单元格“ A1”中。

模式1:

=IMPORTXML(A1,"//img/@src")

enter image description here

模式2:

=IMPORTXML(A1,"//li//@src")

enter image description here

模式3:

=IMPORTXML(A1,"//li[position()>1]//@src")

enter image description here

模式4:

=ARRAYFORMULA("https://www.mikigakki.com"&IMPORTXML(A1,"//li[position()>1]//@src"))

enter image description here

模式5:

=ARRAYFORMULA("https://www.mikigakki.com"&IMPORTXML(A1,"//li[1]//@src"))

enter image description here

参考:

如果我误解了您的问题,而这不是您想要的结果,我深表歉意。

© www.soinside.com 2019 - 2024. All rights reserved.