Skip to content

Commit 04f998d

Browse files
Update current_stock_price.py
1 parent 950ea9c commit 04f998d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

web_programming/current_stock_price.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from doctest import testmod
2-
1+
import requests
32
from bs4 import BeautifulSoup
4-
from requests import get
53

64
"""
75
Get the HTML code of finance yahoo and select the current qsp-price
@@ -22,11 +20,11 @@ def stock_price(symbol: str = "AAPL") -> str:
2220
True
2321
"""
2422
url = f"https://finance.yahoo.com/quote/{symbol}?p={symbol}"
25-
yahoo_finance_source = get(
23+
yahoo_finance_source = requests.get(
2624
url, headers={"USER-AGENT": "Mozilla/5.0"}, timeout=10
2725
).text
2826
soup = BeautifulSoup(yahoo_finance_source, "html.parser")
29-
specific_fin_streamer_tag = soup.find("fin-streamer", {"data-testid": "qsp-price"})
27+
specific_fin_streamer_tag = soup.find("fin-streamer", {"data-test": "qsp-price"})
3028

3129
if specific_fin_streamer_tag:
3230
text = specific_fin_streamer_tag.get_text()
@@ -36,6 +34,8 @@ def stock_price(symbol: str = "AAPL") -> str:
3634

3735
# Search for the symbol at https://finance.yahoo.com/lookup
3836
if __name__ == "__main__":
37+
from doctest import testmod
3938
testmod()
39+
4040
for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
4141
print(f"Current {symbol:<4} stock price is {stock_price(symbol):>8}")

0 commit comments

Comments
 (0)