We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e09bf69 commit 4c75f86Copy full SHA for 4c75f86
web_programming/current_stock_price.py
@@ -0,0 +1,14 @@
1
+import requests
2
+from bs4 import BeautifulSoup
3
+
4
5
+def stock_price(symbol: str = "AAPL") -> str:
6
+ url = f"https://in.finance.yahoo.com/quote/{symbol}?s={symbol}"
7
+ soup = BeautifulSoup(requests.get(url).text, "html.parser")
8
+ class_ = "My(6px) Pos(r) smartphone_Mt(6px)"
9
+ return soup.find("div", class_=class_).find("span").text
10
11
12
+if __name__ == "__main__":
13
+ for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
14
+ print(f"Current {symbol:<4} stock price is {stock_price(symbol):>8}")
0 commit comments