首页 > 解决方案 > Google 表格中的 IMPORTXML 语法问题

问题描述

我正在尝试导入

https://www67.myfantasyleague.com/2019/export?TYPE=players&DETAILS=&SINCE=&PLAYERS=&JSON=0

进入谷歌工作表并清理它,使其成为三列,一列 for player id, nextname和 next team

我已将公式输入到谷歌表格中,我认为它应该如何工作,但我的语法错误,因为我得到了错误

导入的内容为空。

我没有针对正确的数据,我不确定如何在这里准确地做到这一点。

我使用的公式是:

=IMPORTXML("https://www67.myfantasyleague.com/2019/export?TYPE=players&DETAILS=&SINCE=&PLAYERS=&JSON=0","//span[@class='html-attribute-value']")

=IMPORTXML("https://www67.myfantasyleague.com/2019/export?TYPE=players&DETAILS=&SINCE=&PLAYERS=&JSON=0","//span[@class='html-attribute-value']")```

=IMPORTXML("https://www67.myfantasyleague.com/2019/export?TYPE=players&DETAILS=&SINCE=&PLAYERS=&JSON=0","//span[@class='html-attribute-value']")```

这是我的谷歌表: https ://docs.google.com/spreadsheets/d/1W0Bt5z-Tky-tNhG_JtfE4FfjTRgQNRu_eQu2qVhQ-_E/edit?usp=sharing

标签: xmlxpathgoogle-sheetsgoogle-sheets-formulagoogle-sheets-importxml

解决方案


尝试:

=ARRAYFORMULA(IFERROR(QUERY({
 REGEXEXTRACT(INDEX(IMPORTDATA("https://www67.myfantasyleague.com/2019/export?TYPE=players&DETAILS=&SINCE=&PLAYERS=&JSON=0"),,1), "id=""(.+?)"""),
 REGEXEXTRACT(INDEX(IMPORTDATA("https://www67.myfantasyleague.com/2019/export?TYPE=players&DETAILS=&SINCE=&PLAYERS=&JSON=0"),,1), "name=""(.+)")&" "&
 REGEXEXTRACT(INDEX(IMPORTDATA("https://www67.myfantasyleague.com/2019/export?TYPE=players&DETAILS=&SINCE=&PLAYERS=&JSON=0"),,2), "(.+?)"""),
 REGEXEXTRACT(INDEX(IMPORTDATA("https://www67.myfantasyleague.com/2019/export?TYPE=players&DETAILS=&SINCE=&PLAYERS=&JSON=0"),,2), "team=""(.+?)""")}, 
 "offset 3")))

在此处输入图像描述

电子表格演示


推荐阅读