yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

Ticker: 0097.KL missing balance_sheet

Open mrkgoh opened this issue 2 years ago • 2 comments

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

Capture

mrkgoh avatar May 10 '22 15:05 mrkgoh

Here is my attempt at debugging:

  1. 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.

mrkgoh avatar May 11 '22 07:05 mrkgoh

Correct financials are now available in pre-release version 0.2.0rc4.

ValueRaider avatar Dec 15 '22 16:12 ValueRaider