IMPORTXML can't fetch from Yahoo Finance if there is a point in in the ticker

Viewed 477

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.

1 Answers

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

Related