JSON and Scraping
import requests
stock = input('Stock Ticker? ').lower()
while stock != 'quit' and stock != 'exit':
# Build the JSON query
query = 'http://query1.finance.yahoo.com/v11/finance/quoteSummary/' + stock + '?modules=financialData'
with requests.session():
header = {'Connection': 'keep-alive',
'Expires': '-1',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) \
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36'
}
website = requests.get(query, headers=header)
json = website.json()
# Get the currentPrice from JSON
price_dict = json['quoteSummary']['result'][0]['financialData']['currentPrice']
print(stock + ' current price: $' + price_dict['fmt'])
stock = input('Stock Ticker? ').lower()