14
$\begingroup$

There are plenty of sources which provide the historical stock data but they only provide the OHLC fields along with volume and adjusted close. Also a couple of sources I found provide market cap data sets but they're restricted to US stocks. Yahoo Finance provides this data online but there's no option to download it ( or none I am aware of ).

  • Where can I download this data for stocks belonging to various top stock exchanges across countries by using their ticker name ?
  • Is there some way to download it via Yahoo Finance or Google Finance ?

I need data for the last decade or so and hence need some script or API which would do this.

$\endgroup$
7
$\begingroup$

Quant SE is better place for questions related to getting financial data:

$\endgroup$
3
$\begingroup$

As far as gathering data goes, you can check out Quandl (there's a tutorial on using it with R on DataCamp if you're interested).

In addition, Aswath Damodaran's site contains a lot of helpful datasets. Though they aren't updated that frequently, they may still be useful, especially as a benchmark for comparing your own output (from the scripts you will inevitably need to write to calculate the necessary metrics).

And, again, Quant SE is probably a better place to be looking...

$\endgroup$
1
$\begingroup$

Something changed on this web site recently. The code directly below works for me.

import csv
import requests
from bs4 import BeautifulSoup

url_base = "https://finviz.com/quote.ashx?t="
tckr = ['MSFT','AAPL','AMZN','FB','GOOG']

i = 1

url_list = [(s, url_base + s) for s in tckr]

headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0'}

with open('C:\\Users\\ryans\\OneDrive\\Desktop\\AAA.csv', 'w', newline='') as f_out:
    writer = csv.writer(f_out, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
    for t, url in url_list:
        print(i)
        i = i + 1
        print(t, url)
        print('Scrapping ticker {}...'.format(t))
        soup = BeautifulSoup(requests.get(url, headers=headers).content, 'html.parser')
        writer.writerow([t])
        for row in soup.select('.snapshot-table2 tr'):
            writer.writerow([td.text for td in row.select('td')])

I deleted the older, non-working, code.

$\endgroup$
1
  • $\begingroup$ This would require something like sellenium in 2021, you get a DDOS protection message $\endgroup$ Apr 4 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.