I am looking for a Python code that scraps a website to download historical firm data such as market capitalization, dividend-yield, and so on. I have a code that downloads the current firm data from Yahoo but I am looking for historical data. Any suggestions?
You don't have to scrape that data to get it via Python if you work with Intrinio's API. Here is a Python SDKs that will make it easy for you:
Historical financial statements and dividend yield, marketcap, etc: https://github.com/nhedlund/intrinio
Specifically, you can make a curl request for historical marketcap like this:
curl "https://api.intrinio.com/historical_data?identifier=AAPL&item=marketcap&start_date=2014-01-01&end_date=2015-01-01" -u "USERNAME:PASSWORD"
That would give you the marketcap for Apple over the specified dates. You can just swap out the marketcap tag for dividendyield and get the data you want. Here is a full tutorial: