In this tutorial, we use BeautifulSoup and Requests in Python to pull the market cap of a stock (AAPL) from Yahoo Finance. Next, we set our program to run everyday and to send us an sms text message with the results.

#Wayscript #Python #Scrape

Register at https://wayscript.com

Want to clone this script to your own account?
https://wayscript.com/user/derricks/0xQd0ZuX

Follow WayScript on Social Media:
GitHub – https://github.com/wayscript
Twitter – https://twitter.com/WayScriptHQ
Linkedin – https://www.linkedin.com/company/wayscript/
Instagram – https://www.instagram.com/wayscript/
Facebook – https://www.facebook.com/wayscript/

Code from the Tutorial (Updated 4/6/2020)
 » » » »
import requests
from bs4 import BeautifulSoup

ticker = ‘AAPL’
url = ‘https://finance.yahoo.com/quote/‘ + ticker

res = requests.get( url )
html = res.text

soup = BeautifulSoup( html, ‘html.parser’ )
market_cap_elem = soup.find( ‘td’, { ‘data-test’ : ‘MARKET_CAP-value’ } )
market_cap = market_cap_elem.text

print( ticker, ‘Market Cap’, market_cap )

variables[ ‘MarketCap’ ] = market_cap
 » » »