0

I am trying to import stock real-time price, real-time volume and average volume in Google sheet from Yahoo Finance but not sure about XPath to be used for same.

for example, for 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

here I tried to modify below code but not sure about XPath

=INDEX(IMPORTXML("https://sg.finance.yahoo.com/quote/AMZN","//div[@id='quote-header-info']/div[last()]/div[1]"),1)
player0
  • 124,011
  • 12
  • 67
  • 124
MGGameLab
  • 11
  • 1
  • 5

1 Answers1

5

Here are the 3 lines that need.

Real Time Price

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

Volume:

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

Average:

=INDEX(IMPORTXML("https://sg.finance.yahoo.com/quote/AMZN","//td[@data-test='AVERAGE_VOLUME_3MONTH-value']/span"),1)
supputuri
  • 13,644
  • 2
  • 21
  • 39
  • tnx a lot, it worked for single record. But when i am trying to use the same for all NSE F&O stocks, it keeps on loading. Pls. suggest. – MGGameLab May 10 '19 at 11:51
  • @MGGameLab check with the updated xpath for the real time price. Just changed `/span` to `//span`. – supputuri May 10 '19 at 18:05
  • tnx for reply. still taking same time to load.any idea how to refresh xml import after fixed interval? – MGGameLab May 12 '19 at 19:04
  • Hope the core xpath issue is fixed (if so please accept the answer). You can refer to [this post](https://stackoverflow.com/questions/33872967/periodically-refresh-importxml-spreadsheet-function) on refreshing the sheet. – supputuri May 12 '19 at 19:13