Open Sainath26 opened 2 years ago
use y finance instead so the generate function would look something like this,
in the import section : !pip install yfinance import yfinance
and GenerateData section:
def generateData(self): global DataSize
data = []
stock_data = yf.download(Stock_name, start='2022-03-01', end='2023-03-01')
#url = "https://finance.yahoo.com/quote/" + Stock_name + "/history/"
#rows = bs(urllib2.urlopen(url).read(), "lxml").findAll('table')[0].tbody.findAll('tr')
#for each_row in rows:
# divs = each_row.findAll('td')
# if divs[1].span.text != 'Dividend': #Ignore this row in the table
#I'm only interested in 'Open' price; For other values, play with divs[1 - 5]
# data.append({'open': divs[1].span.text, 'Adj close': float(divs[5].span.text.replace(',',''))})
#data[:NumberOfDay]
#print(data)
file = open('stock_data', 'w')
#closes = [c['Adj close'] for c in data]
#opens = [o['open'] for o in data]
oArray = stock_data['Open'].tolist()[::-1]
cArray = stock_data['Adj Close'].tolist()[::-1]
When I run the .py file, this error pops up.
urllib.error.HTTPError: HTTP Error 404: Not Found
the Yahoo finance url is not getting fetched for some reason. Do you know why is that happening?
Also, can you please share what gets stored in the stock data file