From 4c75f863c84e049026135d5ae04e6969fc569add Mon Sep 17 00:00:00 2001 From: vansh bhardwaj <39709733+vansh1999@users.noreply.github.com> Date: Sat, 23 Nov 2019 18:24:06 +0530 Subject: [PATCH] added current stock price (#1590) * added current stock price * Ten lines or less --- web_programming/current_stock_price.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 web_programming/current_stock_price.py diff --git a/web_programming/current_stock_price.py b/web_programming/current_stock_price.py new file mode 100644 index 000000000..df44da4ef --- /dev/null +++ b/web_programming/current_stock_price.py @@ -0,0 +1,14 @@ +import requests +from bs4 import BeautifulSoup + + +def stock_price(symbol: str = "AAPL") -> str: + url = f"https://in.finance.yahoo.com/quote/{symbol}?s={symbol}" + soup = BeautifulSoup(requests.get(url).text, "html.parser") + class_ = "My(6px) Pos(r) smartphone_Mt(6px)" + return soup.find("div", class_=class_).find("span").text + + +if __name__ == "__main__": + for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split(): + print(f"Current {symbol:<4} stock price is {stock_price(symbol):>8}")