yfinance
yfinance copied to clipboard
Ticker: 0097.KL missing balance_sheet
It seems that yfinance doesn't work for Malaysia stocks?
Here are the code:
import yfinance as yf
code2 = '0097.kl' # Malaysia Stock Name Vitrox
m = yf.Ticker(code2)
m.balance_sheet
>>>
Open High Low Close Adj Close Volume
Date
As you can see from the print screen the data exists on Yahoo Finance page: https://finance.yahoo.com/quote/0097.KL/balance-sheet?p=0097.KL
Here is my attempt at debugging:
- First I try to inspect the html I am getting. Not from https://finance.yahoo.com/quote/0097.KL/financial/ but from https://finance.yahoo.com/quote/0097.KL/balance-sheet?p=0097.KL
import requests as _requests
import json as _json
code = '0097.kl'
_SCRAPE_URL_ = 'https://finance.yahoo.com/quote'
ticker_url = "{}/{}".format(_SCRAPE_URL_, code)
head = {
'accept': '*/*',
'accept-encoding': 'gzip, deflate',
'accept-language': 'en-US,en;q=0.9',
'referer': 'https://s.yimg.com/rq/darla/4-10-1/html/r-sf.html',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36',
}
s = _requests.session() # Used session to hopefully load caches
s.get(url=ticker_url, headers=head)
html = s.get(url=ticker_url + f'/balance-sheet?p={code}', headers=head).text
html output as attached html.txt
With a quick Ctrl+F '947,051' which is the last Total Assets number you can see that it resides inside
<span class="Va(m)">Total Assets</span></div><div class="W(3px) Pos(a) Start(100%) T(0) H(100%) Bg($pfColumnFakeShadowGradient) Pe(n) Pend(5px)"></div></div><div class="Ta(c) Py(6px) Bxz(bb) BdB Bdc($seperatorColor) Miw(120px) Miw(100px)--pnclg D(tbc)" data-test="fin-col"><span>947,051</span>
and not inside the 'root.App.main ='
where the package expects it to be.
Correct financials are now available in pre-release version 0.2.0rc4.