Member-only story
Web Scraping Yahoo Finance
Pull financial statements and stock data from any publicly traded company
The code to this blog can be found on my GitHub.
In the business world, it’s important to know the financial health of a company. Looking at the financial statements is a great way to get some insight into how well a company is doing.
In this blog, I’ll go over pulling the financial statements from Yahoo Finance for any company in their database in Python. Because Yahoo Finance uses JavaScript, we utilize a combination of BeautifulSoup and Selenium
Import the Libraries
Let’s start with the necessary libraries:
import pandas as pd
from bs4 import BeautifulSoup
import re
from selenium import webdriver
import chromedriver_binary
import stringpd.options.display.float_format = '{:.0f}'.format
Set up and run the driver
is_link = 'https://finance.yahoo.com/quote/AAPL/financials?p=AAPL'driver = webdriver.Chrome()
driver.get(is_link)
html = driver.execute_script('return document.body.innerHTML;')
soup = BeautifulSoup(html,'lxml')