I am scraping data from yahoo finance all data scraping is working fine. But when I want to store the appended list into an indexable dataframe it returns a blank dataframe however, when I store the data in a non-indexable dataframe it store the data.
When I print temp I can see the data even if I convert temp into a dataframe it gets converted successfully. But when I run financial_dir[ticker]=temp.append(soup.find('div', {'class' : "D(tbrg)"}).find_all('div')[i].get_text(separator='|').split('|')) it does not create an indexable dataframe it runs an empty dataframe.
I want to create financial_dir like this which is callable for different stocks for example when I run financial_dir['INDUSINDBK.NS'] it should give the dataframe for INDUSINDBK.NS like the image. Any help will be extremely appreciated
'''
import requests
from bs4 import BeautifulSoup
import pandas as pd
tickers = ['KOTAKBANK.NS','WIPRO.NS','HINDALCO.NS','RELIANCE.NS',
'INDUSINDBK.NS','HDFCLIFE.NS','TATACONSUM.NS','TITAN.NS',
'ULTRACEMCO.NS']
financial_dir = pd.DataFrame()
temp = []
for ticker in tickers:
url = 'https://finance.yahoo.com/quote/'+ticker+'/financials?p='+ticker
page = requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'})
#page_content = page.content
soup = BeautifulSoup(page.text, 'html.parser')
a = list(range(0,2000,1))
#while IndexError(True):
try:
for i in a:
financial_dir[ticker]=temp.append(soup.find('div', {'class' : "D(tbrg)"}).find_all('div')[i].get_text(separator='|').split('|'))
except:
pass
temp
data5 = pd.DataFrame(temp)
financial_dir
'''