XPath查询以使用importxml提取Google表格中的当前价格,数量和平均数量

时间:2019-04-26 14:30:42

标签: xpath google-sheets yahoo-finance google-sheets-importxml

我试图从Yahoo Finance导入Go​​ogle表格中的股票实时价格,实时交易量和平均交易量,但不确定将XPath用于该交易量。

例如,用于URL

https://sg.finance.yahoo.com/quote/AMZN

under summary tab:
realtime price: 1910.21
volume: https://sg.finance.yahoo.com/quote/AMZN
avg. volume: 4,406,091

在这里,我尝试修改以下代码,但不确定XPath

=INDEX(IMPORTXML("https://sg.finance.yahoo.com/quote/AMZN","//div[@id='quote-header-info']/div[last()]/div[1]"),1)

1 个答案:

答案 0 :(得分:0)

这里是需要的三行。

实时价格

type: 'application/xlsx; charset=utf-8;

音量:

=INDEX(IMPORTXML("https://sg.finance.yahoo.com/quote/AMZN","(//div[@id='quote-header-info']/div[last()]/div[1]//span)[1]"),1)

平均值:

=INDEX(IMPORTXML("https://sg.finance.yahoo.com/quote/AMZN","//td[@data-test='TD_VOLUME-value']/span"),1)