Merge branch 'stock-price-fix' of github.com:Suman2023/Python into stock-price-fix

This commit is contained in:
Suman 2023-08-11 16:12:25 +05:30
commit 0e6f82784f

View File

@ -4,15 +4,16 @@ from bs4 import BeautifulSoup
def stock_price(symbol: str = "AAPL") -> str:
url = f"https://finance.yahoo.com/quote/{symbol}?p={symbol}"
yahoo_finance_source = requests.get(url,headers={'USER-AGENT': "Mozilla/5.0"}).text
yahoo_finance_source = requests.get(url, headers={"USER-AGENT": "Mozilla/5.0"}).text
soup = BeautifulSoup(yahoo_finance_source, "html.parser")
specific_fin_streamer_tag = soup.find('fin-streamer', {'data-test': 'qsp-price'})
specific_fin_streamer_tag = soup.find("fin-streamer", {"data-test": "qsp-price"})
if specific_fin_streamer_tag:
text = specific_fin_streamer_tag.get_text()
return text
return "No <fin-streamer> tag with the specified data-test attribute found."
# Search for the symbol at https://finance.yahoo.com/lookup
if __name__ == "__main__":
for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():