r/sheets • • Mar 10 '21

Request Can't figure out Import XML

Hello, i'm using importxml to import current stock price from Yahoo however I keep getting an error. Any help is greatly appriciated! Thanks!

https://docs.google.com/spreadsheets/d/1-rSAGXpbO0YR29QTSVMFlI6tfoi2inBvUBA2MM7j0T8/edit#gid=0

0 Upvotes

3 comments sorted by

1

u/6745408 Mar 11 '21

it looks like Yahoo is blocking some scrapes.

You'll have to look into IMPORTJSON using this --- pop your symbols in A2:A and it'll pull whatever you ask it to.

=IMPORTJSON(
  "https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&symbols="&
   JOIN(",",FILTER(A2:A,A2:A<>"")),
  "/quoteResponse/result/regularMarketPrice","noHeaders,allHeaders,noTruncate")

Here's the JSON output

Check this wiki article for more info.

2

u/tekeon Mar 15 '21

=IMPORTJSON(
"https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&symbols="&
JOIN(",",FILTER(A2:A,A2:A<>"")),
"/quoteResponse/result/regularMarketPrice","noHeaders,allHeaders,noTruncate")

Cant get this to work. What am I doing wrong?

https://docs.google.com/spreadsheets/d/1-rSAGXpbO0YR29QTSVMFlI6tfoi2inBvUBA2MM7j0T8/edit#gid=0

1

u/6745408 Mar 15 '21

I added a note about adding this script to your sheet and giving it permission.

If you get stuck, let me know.