Skip to content

Commit 4c75f86

Browse files
vansh1999cclauss
authored andcommitted
added current stock price (TheAlgorithms#1590)
* added current stock price * Ten lines or less
1 parent e09bf69 commit 4c75f86

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)