使用相对xpath来刮取自定义div属性

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

我有几百个URL,我正试图刮取页面上图像的图像路径。每个页面的格式相同,但div类对每个页面都是唯一的。

我希望能够在Google工作表中使用import xml来仅删除data-path元素的内容。

我已经尝试过并且未能使用xpath来提取URL。

<div class="uniqueid active" data-path="/~/media/Images/image.jpg" data-alt="Anything"></div>

例如。 //div[@class='*']/@data-path"

网站示例:https://www.cannondale.com/en/Australia/Bike/ProductDetail?Id=77d3b8fe-41f7-42b6-bf69-b5cf0ae55548&parentid=undefined

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

如果div类具有模式"uniqueid active",那么您可以尝试以下XPath:

//div[contains(@class, "active")]/@data-path

否则,如果div类可以是任何内容,请使用此查询:

//div[@class]/@data-path

更新:

我试图用IMPORTXML获取data-path属性的值,但没有成功。尝试使用Python(requestslxml)来做它,它的工作原理。所以可能问题出现在Google表格中 - 一些限制或错误,idk。

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