我正在Google表格中使用以下公式提取一些财务数据:
=TRANSPOSE(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT,"table",4))
IMPORTHTML
结果是
Forward Annual Dividend Rate 4 2.04
Forward Annual Dividend Yield 4 1.11%
Trailing Annual Dividend Rate 3 1.94
Trailing Annual Dividend Yield 3 1.05%
5 Year Average Dividend Yield 4 2.02
Payout Ratio 4 32.93%
Dividend Date 3 Mar 11, 2020
Ex-Dividend Date 4 Feb 18, 2020
Last Split Factor 2 2:1
Last Split Date 3 Feb 17, 2003
我是TRANSPOSING
准备查询数据的结果:
Forward Annual Dividend Rate 4 Forward Annual Dividend Yield 4 Trailing Annual Dividend Rate 3 ...
2.04 1.11% 1.94 ...
[我需要的是Ex-Dividend Date 4
列的值(因此:Feb 18, 2020
)(后来还有其他列,因此我正在寻求通用解决方案)。我尝试了多种方法(请参阅下文,但所有方法均会导致#VALUE!
错误:
=QUERY(TRANSPOSE(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT","table",4)), "SELECT * LIMIT 2 OFFSET 1 WHERE COL=""Ex-Dividend Date 4"")")
=QUERY(TRANSPOSE(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT","table",4)), "SELECT [Ex-Dividend Date 4] LIMIT 2 OFFSET 1")
如何正确查询该表?
尝试:
=INDEX(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT",
"table", 4), 8, 2)
或已格式化:
=TEXT(INDEX(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT",
"table", 4), 8, 2), "mm/dd/yyyy")
在QUERY
中:
=QUERY(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT",
"table", 4), "select Col2 where Col1 contains 'Ex-Dividend Date 4'", 0)
使用QUERY
,您也可以尝试:
=QUERY(TRANSPOSE(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT","table",4)), "select Col8")