You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'''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
The text was updated successfully, but these errors were encountered:
I try to correct the code :
def get_income_statement(ticker, yearly = True):
The text was updated successfully, but these errors were encountered: