如何在 Google 电子表格中使用 ImportXML 返回多列数据?
我在 Google 电子表格中使用 ImportXML
来访问 Twitter API 中的user_timeline
方法。我想从响应中提取 created_at
和 text
字段,并创建结果的两列显示。
目前,我通过调用 API 两次来实现此目的,一次是
=ImportXML("http://twitter.com/status/user_timeline/matthewsim.xml?count=200","/statuses/status/created_at")
在一列顶部的单元格中,另一次是
=ImportXML("http://twitter.com/status/user_timeline/matthewsim.xml?count=200","/statuses/status/text")
在另一列顶部的单元格中。
有没有办法让我通过一次调用来创建此显示?
I'm using ImportXML
in a Google Spreadsheet to access the user_timeline
method in the Twitter API. I'd like to extract the created_at
and text
fields from the response and create a two-column display of the results.
Currently I'm doing this by calling the API twice, with
=ImportXML("http://twitter.com/status/user_timeline/matthewsim.xml?count=200","/statuses/status/created_at")
in the cell at the top of one column, and
=ImportXML("http://twitter.com/status/user_timeline/matthewsim.xml?count=200","/statuses/status/text")
in another.
Is there a way for me to create this display with a single call?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将 =CONTINUE() 的行转换为列的另一种方法是使用 transpose():
Another way to convert the rows of =CONTINUE() into columns is to use transpose():
ImportXML 支持使用 xpath
|
分隔符来包含任意数量的查询。但是,它没有将结果扩展为多列。您将获得一列重复的三元组(或者无论您选择多少个属性),如下面的
A
列中所示。以下内容已于
2015 年 6 月 16 日弃用:
继续
在“新版 Google 表格”中不可用(请参阅:Google 文档 for继续
)。但是,您不需要使用自动插入的
CONTINUE ()
函数来放置结果。放置在
B2
中,应该干净地向下和向右填充,以便为您提供理智的列数据。A2
中。A3
及以下内容是自动填充CONTINUE()
函数的方式。A1
是属性的数量。B1:D1
是其列的属性索引。ImportXML supports using the xpath
|
separator to include as many queries as you like.However it does not expand the results into multiple columns. You get a single column of repeating triplets (or however many attributes you've selected) as shown below in column
A
.The following is deprecated
2015.06.16:
continue
is not available in "the new Google Sheets" (see: The Google Documentation forcontinue
).However you don't need to use the automatically inserted
CONTINUE()
function to place your results.Placed in
B2
that should cleanly fill down and right to give you sane column data.A2
.A3
and below are how theCONTINUE()
functions are automatically filled in.A1
is the number of attributes.B1:D1
are the attribute index for their columns.只需用“|”连接您的查询即可
Just concatenate your queries with "|"
这是下面评论中发布的最佳解决方案(不是我的)。老实说,我不确定它是如何工作的。也许原发帖者@Pandora 可以提供一个解释。
特别是,如果知道如何修改公式以容纳更多列,那就太好了。
This is the best solution (NOT MINE) posted in the comments below. To be honest, I'm not sure how it works. Perhaps @Pandora, the original poster, could provide an explanation.
In particular, it would be good to know how to modify the formula to accommodate more columns.
我向 Google 支持论坛提出了这个问题,这是一个对我有用的解决方案:
用您的数据和查询替换 IMPORTXML 的内容,看看这是否适合您。显然
,这仅尝试调用 IMPORTXML 函数一次。至少目前这是一个解决方案。
这是完整线程。
I posed this question to the Google Support Forum and this is was a solution that worked for me:
Replace the contents of IMPORTXML with your data and query and see if that works for you. I
Apparently, this attempts to invoke the IMPORTXML function only once. It's a solution for now, at least.
Here's the full thread.