I am new to python and would love to know this. Suppose I want to scrape stock price data from a website to excel. Now the data keeps refreshing every second, how do I refresh the data on my excel sheet automatically using python. I have read about win32 but couldn’t understand it’s use much. Any help would be dearly appreciated.
-
1It depends on how do you want to do it. Method 1. Do it yourself: Find out if the website allow data scrapping or offers APIs you could use. Libraries like requests, beautifulsoup and pandas could be use to gather, clean and transform your data to the format you want. Your script can the placed on crontab or task scheduler to be ran at N intervals updating your data – Prayson W. Daniel Aug 09 '18 at 17:16
-
1Method 2: Use available library like quandl or findatapy to fetch data and store it on your excel. Similarly place it schedule the script to run at N interval :) – Prayson W. Daniel Aug 09 '18 at 17:24
-
That’s great! How does crontab work? Any code that would be useful? Secondly: quandl and findatapy are python libraries? – ShreyGrover Aug 09 '18 at 17:25
-
Yes, they are python libraries you can use. If you visit github, you can view dozen of examples. Search in GitHub stock, filter Python. You can Google “crontab” ;) – Prayson W. Daniel Aug 09 '18 at 19:42
-
BTW: Can you share what you have tried? Which site are planning to harvest your data? What are their usage policies? – Prayson W. Daniel Aug 09 '18 at 19:48
-
I wish to gather data from https://in.finance.yahoo.com/quote/%5ENSEI?p=^NSEI&.tsrc=fin-srch-v1 I am not sure about the usage policy. – ShreyGrover Aug 10 '18 at 07:34
-
You can start here: https://stackoverflow.com/questions/49705047/downloading-mutliple-stocks-at-once-from-yahoo-finance-python – Prayson W. Daniel Aug 10 '18 at 10:40
3 Answers
Use requests module if the site has direct API to download the data. Try checking the developer tool(F12) to view the network api call details.

- 590
- 1
- 7
- 13
You can go throw Q49705047 Downloading multiple stocks at once from yahoo finance python as it captures what you are looking for. Happy coding :)

- 14,191
- 4
- 51
- 57
You can always try my new module, YahooFinancials, for this. I have already coded most of what you will end up having to code and then some. YahooFinancials returns price data for stocks, indexes, cryptocurrencies, currencies, and commodities. Also no webdriver is required to run this module. 100% requests and bs4.
Installation is easy:
$ pip install yahoofinancials
or
> python -m pip install yahoofinancials
Usage is also easy and all data is returned in a consistent JSON format. You can run one stock at a time by inputting a symbol as a string, or run many stocks/assets at once by inputting the tickers in a list of ticker strings.
For example,
from yahoofinancials import YahooFinancials
tech_stocks = ['AAPL', 'MSFT', 'INTC']
bank_stocks = ['WFC', 'BAC', 'C']
yahoo_financials_tech = YahooFinancials(tech_stocks)
yahoo_financials_banks = YahooFinancials(bank_stocks)
print(yahoo_financials_tech.get_current_price())
print(yahoo_financials_banks.get_current_price())
Returns
{'AAPL': 209.24, 'INTC': 48.4733, 'MSFT': 109.23}
and
{'WFC': 57.96, 'C': 69.683, 'BAC': 30.605}
You can always run that in a while loop with a delay while waiting for new price changes.
You can also pull historical price data with daily, weekly, and monthly intervals like so:
yahoo_financials = YahooFinancials('WFC')
print(yahoo_financials.get_historical_price_data("2018-07-10", "2018-08-10", "monthly"))
Which returns:
{
"WFC": {
"currency": "USD",
"eventsData": {
"dividends": {
"2018-08-01": {
"amount": 0.43,
"date": 1533821400,
"formatted_date": "2018-08-09"
}
}
},
"firstTradeDate": {
"date": 76233600,
"formatted_date": "1972-06-01"
},
"instrumentType": "EQUITY",
"prices": [
{
"adjclose": 57.19147872924805,
"close": 57.61000061035156,
"date": 1533096000,
"formatted_date": "2018-08-01",
"high": 59.5,
"low": 57.08000183105469,
"open": 57.959999084472656,
"volume": 138922900
}
],
"timeZone": {
"gmtOffset": -14400
}
}
}
If you are interested in learning more, feel free to check us out at https://github.com/JECSand/yahoofinancials for more details and examples! We have dozens of different useful financial data methods now that return both fundamental and technical data.
Hope this helps you. Also a live streaming price feed is in the works for the next major release!

- 171
- 1
- 4