import requests from bs4 import BeautifulSoup def get_stock_data(symbol): url = f"https://finance.yahoo.com/quote/{symbol}" response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') data = {} data['symbol'] = symbol data['price'] = soup.find_all('div', {'class': 'My(6px) Pos(r) smartphone_Mt(6px)'})[0].find('span').text data['change'] = soup.find_all('div', {'class': 'My(6px) Pos(r) smartphone_Mt(6px)'})[0].find_all('span')[1].text return data def get_news(symbol): url = f"https://finance.yahoo.com/quote/{symbol}/news?p={symbol}" response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') news = [] for item in soup.find_all('h3', {'class': 'Mb(5px)'}): news_item = {} news_item['title'] = item.text news_item['link'] = item.find('a')['href'] news.append(news_item) return news symbol = input("Please enter a stock symbol: ") print(get_stock_data(symbol)) print(get_news(symbol))