【问题标题】:IMPORTXML() only works on a part of the xPathIMPORTXML() 仅适用于 xPath 的一部分
【发布时间】:2018-11-12 10:36:26
【问题描述】:

我想从此处找到的资产负债表信息中下载部分(即特定行和列...单元格):

https://www.barchart.com/stocks/quotes/AAPL/balance-sheet/annual

在 Chrome 中使用“xPath”:

/html/body/div[2]/div/div[2]/div[2]/div/div[2]/div/div/div/div[3]/div[2]/div/ng-transclude/table/tbody/tr[4]/td[3]

在 Chrome 中使用“xPath Helper”:

/html/body/div[@id='bc-main-content-wrapper']/div[@class='inner-wrap']/div[@class='main-content-wrapper content js-main-content-wrapper ']/div[@class='row']/div[@class='large-12 columns']/div[@class='one-column-block']/div[@class='row']/div[@id='main-content-column']/div[@class='column-inner']/div[@class='bc-financial-report']/div[@class='bc-table-scrollable']/div[@class='bc-table-scrollable-inner']/ng-transclude/table[@class='ng-scope']/tbody/tr[4]/td[3]

但我只能从网页中返回包含部分路径的所有数据 - 即:

=IMPORTXML(A1,"/html/body/div[2]/div/div[2]/div[2]/div/div[2]/div/div/div/div[3]")

和:

=IMPORTXML(A1,"/html/body/div[@id='bc-main-content-wrapper']/div[@class='inner-wrap']/div[@class='main-content-wrapper content js-main-content-wrapper']/div[@class='row']/div[@class='large-12 columns']/div[@class='one-column-block']/div[@class='row']/div[@id='main-content-column']/div[@class='column-inner']/div[@class='bc-financial-report']")

最初我认为它与 'ng-transclude'-section 有关...但正如您所见,我什至没有到达路径的那部分。

我希望有人能指出解决这个问题的正确方向。

【问题讨论】:

    标签: xml xpath google-sheets


    【解决方案1】:

    也许:

    对于整行:=index(importhtml("https://www.barchart.com/stocks/quotes/AAPL/balance-sheet/annual","table"),7,)Inventories 的示例)。

    对于整列:=index(importhtml("https://www.barchart.com/stocks/quotes/AAPL/balance-sheet/annual","table"),,3)09-2017 的示例)。

    对于单元格:=index(importhtml("https://www.barchart.com/stocks/quotes/AAPL/balance-sheet/annual","table"),7,3)Inventories 的示例为 09-2017)。

    【讨论】:

    • 感谢 pnuts 提供的非常优雅且内容丰富的解决方案!附带说明 - 我设法通过谷歌脚本访问数据 - 以下方式(不太漂亮 - 但它有效):doc.html.body.div[1].div.div[1].div[1] .div.div[1].div.div.div.div[2].getElements()[1].table.tbody.tr[index].td[3].getText().replace("$", "").split(",").join("");
    猜你喜欢
    • 2013-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    相关资源
    最近更新 更多