2

Basically the title: I can fetch data from Yahoo Finance for ASML ticker by

=IMPORTXML("https://finance.yahoo.com/quote/ASML/", "//*[@id=""quote-header-info""]/div[3]/div[1]/div/span[1]")

but it doesn't work if there a point/dot "." in the ticker:

=IMPORTXML("https://finance.yahoo.com/quote/ASML.AS/", "//*[@id=""quote-header-info""]/div[3]/div[1]/div/span[1]")

returning the infamous

#N/A

error. I would appreciate it if you could help me know what is the problem and how I can resolve it.

P.S.1 Please note that the above URLs are both valid pointing towards different stocks.

P.S.2. I wrote a relevant post here.

P.S.3. The same issue was also identified by this post.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193

1 Answers1

2

I do not know why all tickers with dots are not returning properly, but you can try using Apps Script as alternative via UrlFetchApp.fetch and use this custom function I created.

Script:

function customImportXML(link) {
  var regex = /span class="Trsdu\(0.3s\) Fw\(b\) Fz\(36px\) Mb\(-4px\) D\(ib\)"[^>]*>([^<]*)</g;
  return regex.exec(UrlFetchApp.fetch(link).getContentText())[1];
}

I used the class as identifier as the data-reactid is not permanent.

output

NightEye
  • 10,634
  • 2
  • 5
  • 24
  • 1
    Hi @Foad, there is an option below that let's you proceed. It says unsafe and continue i believe. Just allow the script to have permission and you should be able to use that. – NightEye Jul 17 '21 at 08:10
  • No there isn't any option to do anything. This is a prevalent issue apparently with no clear solution as far as I can see. – Foad S. Farimani Jul 21 '21 at 09:49