如果股票代码中有一个点,则无法从雅虎财经获取 IMPORTXML [英] IMPORTXML can't fetch from Yahoo Finance if there is a point in in the ticker
问题描述
基本上是标题:我可以从 Yahoo Finance 获取数据,用于 ASML
股票代码
=IMPORTXML("https://finance.yahoo.com/quote/ASML/", "//*[@id=""quote-header-info""]/div[3]/div[1]/div/span[1]")
但是如果有一个点/点.
"它不起作用在代码中:
=IMPORTXML("https://finance.yahoo.com/quote/ASML.AS/", "//*[@id="""quote-header-info""";]/div[3]/div[1]/div/span[1]")
回归臭名昭著
<块引用>#不适用
错误.如果您能帮助我了解问题所在以及如何解决,我将不胜感激.
P.S.1请注意,以上网址均指向不同的股票.
P.S.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.
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.
这篇关于如果股票代码中有一个点,则无法从雅虎财经获取 IMPORTXML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!