GoogleSheets 以自己的方式解析页面(父 >> 子结构与浏览器中的不完全相同)。在 XPath 中使用 //tr 来规避解析错误:
=IMPORTXML("https://discgolfmetrix.com/?u=scorecard&ID=1172639&view=result","//table[@class='data data-hover']//tr/td[2]")
或者使用IMPORTHMTL和QUERY:
=QUERY(IMPORTHTML("https://discgolfmetrix.com/?u=scorecard&ID=1172639&view=result","table",1),"select Col2 OFFSET 1")
输出:
EDIT:更多详情:
对于第一个链接,解析后的 HTML 结构如下:
<table>
<tr>
<td></td>
<td>your_data</td>
...
</tr>
<tr>
<td></td>
<td>your_data</td>
...
</tr>
...
</table>
而且您的 XPath 可以正常工作。
对于第二个链接,前面有一个 tbody 元素,其中包含 tr 元素。结构是:
<table>
<tbody>
<tr>
<td></td>
<td>your_data</td>
...
</tr>
<tr>
<td></td>
<td>your_data</td>
...
</tr>
...
</tbody>
</table>
你的 XPath 失败了。这就是为什么你必须使用// 或在你的表达式中声明tbody 元素:
=IMPORTXML("https://discgolfmetrix.com/?u=scorecard&ID=1172639&view=result","//table[@class='data data-hover']/tbody/tr/td[2]")