Written in Python.
This purpose of this program is to scrape analyst ratings of a user given stock and displays the data using plotly. Analyst ratings can be used in trading strategies.
DOES NOT SCRAPE ETF RATINGS
Two files:
- Analyst_Rating.py, which is used to scrape websites and create a pandas dataframe
- plotly_Analyst_Rating.py, calls Analyst_Rating.py and creates pie charts. plotly_Analyst_Rating.py is the file you must run
Websites used for scraping using BeautifulSoup:
- swingtradebot.com
- zacks.com
- wsj.com
Websites used for scraping using selenium (since BeautifulSoup was unable to scrape on these sites)
- Thestreet.com
- tradingview.com
Pandas data frame was used to hold analyst ratings and the website names. The data frame was then used for pie charts that were powered by plotly. There is a pie chart for each site and a pie chart for all ratings combined.
- bs4
- requests
- yfinance
- pandas
- selenium
- time
- plotly
from bs4 import BeautifulSoup as bs # To parse HTML
import requests # To open links
import yfinance as yf # Check if the ticker entered is valid, also grabs the ticker's exchange (NYSE, NASDAQ, etc)
import pandas as pd # Used for a data frame table to hold ratings, and analysts
import selenium.common
from selenium import webdriver # To scrape JavaScript, used for Tradingview.com and TheStreet.com
import time # Testing time it takes for scraping
# imports below are for plotly and are used in plotly_Analyst_Ratings.py
from plotly.subplots import make_subplots # making multiple charts
import plotly.graph_objects as go # making a chart
On line 131 you need to specify where your chromedriver is located
driver = webdriver.Chrome("/Users/Suraj/Downloads/chromedriver", options=options)
When the stock "teva" is entered by the user:
When "aim" is entered by the user:
When "aaple" is entered by the user: