【问题标题】:Google Sheet Import Data in Tables (ImportXML and ImportHTML Not Working)表格中的 Google 工作表导入数据(ImportXML 和 ImportHTML 不起作用)
【发布时间】:2019-07-22 00:55:27
【问题描述】:

我正在尝试将下面链接的表格(Fangraphs)中显示的数据拉到我的 Google 表格中。

链接到网站上的表格:

https://www.fangraphs.com/leaders/splits-leaderboards?splitArr=8,131&splitArrPitch=&position=B&autoPt=false&splitTeams=false&statType=player&statgroup=2&startDate=2014-03-01&endDate=2019-11-01&players=&filter=AB%7Cgt%7C5&sort=16,1&pageitems=10000000000000&pagenum=0

使用 ImportHTML,我只能从链接中提取表 #1、2、3,它们都不是正确的表。

使用 ImportXML,我不断收到使用代码的公式解析错误:

=IMPORTXML("https://www.fangraphs.com/leaders/splits-leaderboards?splitArr=8,131&splitArrPitch=&position=B&autoPt=false&splitTeams=false&statType=player&statgroup=2&startDate=2014-03-01&endDate=2019-11-01&players=&filter=AB%7Cgt%7C5&sort=16,1&pageitems=10000000000000&pagenum=0","//*[@id="react-drop-test"]/div[2]/div/div[1]/div/div[1]/table)")

我试过的代码:

导入HTML:

=IMPORTHTML("https://www.fangraphs.com/leaders/splits-leaderboards?splitArr=8,131&splitArrPitch=&position=B&autoPt=false&splitTeams=false&statType=player&statgroup=2&startDate=2014-03-01&endDate=2019-11-01&players=&filter=AB%7Cgt%7C5&sort=16,1&pageitems=10000000000000&pagenum=0", "table",4)

导入XML:

=IMPORTXML("https://www.fangraphs.com/leaders/splits-leaderboards?splitArr=8,131&splitArrPitch=&position=B&autoPt=false&splitTeams=false&statType=player&statgroup=2&startDate=2014-03-01&endDate=2019-11-01&players=&filter=AB%7Cgt%7C5&sort=16,1&pageitems=10000000000000&pagenum=0","//*[@id="react-drop-test"]/div[2]/div/div[1]/div/div[1]/table)")```

I want the table headers and all the data below to be pulled into my Google sheet.  I've done this with other Fangraph links.

【问题讨论】:

    标签: xpath google-sheets html-table google-sheets-formula google-sheets-importxml


    【解决方案1】:

    很遗憾,这是不可能的,因为该网站由 JavaScript 控制,而 Google 表格无法理解/导入 JS。您可以通过禁用给定链接的 JS 来测试这一点,您将看到一个空白页面:

    【讨论】:

    • 该死,谢谢。那为什么同一个网站允许我导入html表格呢? =IMPORTHTML("https://www.fangraphs.com/leaders.aspx?pos=all&stats=bat&lg=all&qual=10&type=1&season=2019&month=1&season1=2019&ind=0&team=0&rost=1&age=0&filter=&players=0&page=1_500","table",13)
    • @crocskin77 很好,因为该特定元素不受 JavaScript 控制。只有 JS 内容无法抓取
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多