mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 18:38:39 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
7d27480e25
commit
df0e844223
@ -4,9 +4,9 @@ from bs4 import BeautifulSoup
|
|||||||
|
|
||||||
def stock_price(symbol: str = "AAPL") -> str:
|
def stock_price(symbol: str = "AAPL") -> str:
|
||||||
url = f"https://finance.yahoo.com/quote/{symbol}?p={symbol}"
|
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")
|
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:
|
if specific_fin_streamer_tag:
|
||||||
text = specific_fin_streamer_tag.get_text()
|
text = specific_fin_streamer_tag.get_text()
|
||||||
@ -15,6 +15,7 @@ def stock_price(symbol: str = "AAPL") -> str:
|
|||||||
print("No <fin-streamer> tag with the specified data-test attribute found.")
|
print("No <fin-streamer> tag with the specified data-test attribute found.")
|
||||||
return "Not Found"
|
return "Not Found"
|
||||||
|
|
||||||
|
|
||||||
# Search for the symbol at https://finance.yahoo.com/lookup
|
# Search for the symbol at https://finance.yahoo.com/lookup
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
|
for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user