You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过IMPORTXML的XPath查询获取<tr>下的独立<td>子节点?

Solution for Splitting IMPORTXML Results into Rows in Google Sheets

Let's tackle your issue step by step. The core problem here is that Google Sheets tends to render sibling <td> elements from the same <tr> as adjacent cells in a single row, rather than splitting them into separate rows. Here's how to fix it:

1. Transpose Results to Vertical Rows

The simplest fix is to directly target the <td> elements under your specific <tr>, then use TRANSPOSE to flip the horizontal results into vertical rows.

Try this formula:

=TRANSPOSE(IMPORTXML("https://www.dotabuff.com/matches/5011379854","//tr[contains(@class,'9764136')]/td"))

Why this works:

  • The XPath //tr[contains(@class,'9764136')]/td explicitly selects every <td> that's a direct child of your target <tr> (no extra parent checks needed).
  • TRANSPOSE converts the horizontal array of <td> values (which would normally fill a single row) into a vertical list, with each value in its own row.

2. Split Concatenated Text (If Transpose Doesn't Work)

If you're still seeing values merged into one cell, you can first join all <td> text with a newline character, then split it into separate rows:

=SPLIT(TEXTJOIN(CHAR(10), TRUE, IMPORTXML("https://www.dotabuff.com/matches/5011379854","//tr[contains(@class,'9764136')]/td")), CHAR(10))

How this works:

  • TEXTJOIN(CHAR(10), TRUE, ...) combines all <td> contents into a single string, separated by line breaks.
  • SPLIT(..., CHAR(10)) breaks that string apart at each line break, automatically placing each segment into its own row.

Quick Note on Your Original XPath

Your original formula //td[parent::tr[contains(@class,'9764136')]] does select the correct <td> elements, but Google Sheets displays sibling <td>s from the same <tr> as side-by-side cells. The transpose or split methods above reformat this output to match your "each on its own row" requirement.

If the contains(@class,'9764136') is too broad (risking matching other rows with similar class names), use an exact match instead:

//tr[@class='9764136']/td

Just make sure the class name is exactly 9764136 (no extra spaces or classes) for this to work.

内容的提问来源于stack exchange,提问作者Lemth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:27:06