如何在Google Sheets中为IMPORTXML找出正确的xpath - NA错误?

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

我试图在Google Sheets中使用IMPORTXML功能。

例如,我想在Google Sheets中使用IMPORTXML函数。=IMPORTXML("https://www.tiktok.com/@charlidamelio?lang=en", XMLPATH) 应该返回 "54.3M"

我使用Chrome浏览器检查器复制xpath,得到的结果是。

/html/body/div[1]/div/div[2]/div/div[1]/div/header/h2[1]/strong[2]

当我在Google Sheets中尝试时,它返回一个错误: #NA(导入内容为空)。

P.S.我愿意用其他方法把我需要的数据导入google sheet中,它不一定非要用importXML函数。

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

这个答案怎么样?

在这个答案中。IMPORTXMLREGEXEXTRACT 被使用。而且,它还假设了URL的 https://www.tiktok.com/@charlidamelio?lang=en 被放在 "A1 "单元格中。

模式1.在这个模式中,"followerCount "被检索出来。

在这个模式中,"followerCount "被检索出来。

公式示例:从脚本中获取 "followerCount"。

=REGEXEXTRACT(IMPORTXML(A1,"//script[@id='__NEXT_DATA__']"),"followerCount"":(\d+)")
  • "followerCount "是从脚本中获取的。
  • 在本例中,当 =VALUE(REGEXEXTRACT(IMPORTXML(A1,"//script[@id='__NEXT_DATA__']"),"followerCount"":(\d+)")) 使用,检索到的值可以作为数字使用。

结果。

enter image description here

模式2:

在这个模式中,检索的是 "followerCount"。

示例公式。

=REGEXEXTRACT(IMPORTXML(A1,"//meta[@name='description']/@content")," ([\w\d.]+) Fans")
  • 从元数据中检索出 "5440万粉丝 "的值。

结果:模式2:在这个模式中,"followerCount "被检索到。

enter image description here

引用。

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