首页 > 解决方案 > 如何通过 IMPORTXML 从 Google 表格中的图书网站获取维度

问题描述

这就是我使用谷歌表格获取产品详细信息的方式

=IMPORTXML("https://www.bookdepository.com/Wings-of-War-James-P-Busha/9780760348529","//ul[@class='biblio-info']//li//span") 

但我只需要维度。我怎样才能拿到那个?

我已经尝试了 3 天,但似乎无法弄清楚。太感谢了!

标签: google-sheets-formulaxpath-2.0

解决方案


您可以使用 Chrome 的 DevTools (F12) 获取 XPath。

=IMPORTXML("https://www.bookdepository.com/Wings-of-War-James-P-Busha/9780760348529","/html/body/div[2]/div[5]/div/div/div[1]/div[3]/div/ul/li[2]/span")

选择:

=IMPORTXML("https://www.bookdepository.com/Wings-of-War-James-P-Busha/9780760348529","//ul[@class='biblio-info']//li[2]//span")

仅提取维度:

=TRIM(REGEXEXTRACT(IMPORTXML("https://www.bookdepository.com/Wings-of-War-James-P-Busha/9780760348529","//ul[@class='biblio-info']//li[2]//span"),"^(.+)\|"))

推荐阅读