Create a Python project to get the current stock price of specified companies
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
#Source: https://bit.ly/2KHn1ZW
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 ABM A".split():
print(f"Current {symbol:<4} stock price is: {stock_price(symbol):>8}")أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال