Ken
Ken

Reputation: 1471

How to collect data in range from Yahoo Finance?

I am using a script which uses this line:

    res = requests.get('https://query1.finance.yahoo.com/v8/finance/chart/{symbol}?range={data_range}&interval={data_interval}'.format(**locals()))

to collect stock data from Yahoo Finance. Currently, I am inputting values such as '1d' for data_range which gives me the data from the past day. However, what do I enter if I want to collect data say from 2020-11-24 to 2020-11-25 (instead of from past x days)?

Upvotes: 0

Views: 844

Answers (2)

razimbres
razimbres

Reputation: 5015

Do the following

#!pip install pandas-datareader

import pandas as pd
from pandas_datareader import data

stock = 'RENT3.SA'
source = 'yahoo'

# Set date range
start = datetime.datetime(2019, 8, 19)
end = datetime.datetime(2020, 11, 27)

# Collect stock data
dataset = data.DataReader(stock, source, start, end)

goog_df['Adj Close'].plot(kind='line', grid=True, title='RENT3 Adjusted Closes')

Upvotes: 1

Richard Taujenis
Richard Taujenis

Reputation: 64

I would suggest using the Selenium library.Because you need to handle click event and for the page to relode to get the new updated stock data check bellow

http://lmari.hatenablog.com/entry/selenium-fin

Upvotes: 1

Related Questions