0

我正在尝试从 Yahoo Finance 导入 Google 表格中的股票实时价格、实时交易量和平均交易量,但不确定 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)
4

1 回答 1

5

这是需要的 3 行。

实时价格

=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)

平均:

=INDEX(IMPORTXML("https://sg.finance.yahoo.com/quote/AMZN","//td[@data-test='AVERAGE_VOLUME_3MONTH-value']/span"),1)
于 2019-04-26T16:54:02.843 回答