added current stock price (#1590)

* added current stock price

* Ten lines or less
This commit is contained in:
vansh bhardwaj 2019-11-23 18:24:06 +05:30 committed by Christian Clauss
parent e09bf69648
commit 4c75f863c8

View File

@ -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}")