atreadw1492 / yahoo_fin

Scrape stock price history from new (Spring 2017) Yahoo Finance layout
MIT License
292 stars 125 forks source link

problem with get_income_data #102

Open warren67210 opened 1 year ago

warren67210 commented 1 year ago

I try to correct the code :

def get_income_statement(ticker, yearly = True):

'''Scrape income statement from Yahoo Finance for a given ticker

   @param: ticker
'''

income_site = "https://finance.yahoo.com/quote/" + ticker + "/financials?p=" + ticker
response = requests.get(income_site)
html = response.text
print(f"html: {html}")
# Parse the list of scripts using a regular expression pattern
pattern = r'root\.App\.main = (.*?);\n}(this));'

script_data = re.search(pattern, html, flags=re.DOTALL).group(1)

json_info = json.loads(script_data)

if yearly:
    temp = json_info["context"]["dispatcher"]["stores"]["QuoteSummaryStore"]["incomeStatementHistory"]["incomeStatementHistory"]
else:
    temp = json_info["context"]["dispatcher"]["stores"]["QuoteSummaryStore"]["incomeStatementHistoryQuarterly"]["incomeStatementHistory"]

return _parse_table(temp) 

But i got always the TypeError: string indices must be integers
drhdev commented 1 year ago

same here. looks broken.

yaz231 commented 9 months ago

Same for me. Not sure if anyone has found a workaround?