Skip to content

Commit 9a8e2c7

Browse files
authored
Update current_stock_price.py
1 parent 5f33173 commit 9a8e2c7

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

web_programming/current_stock_price.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def stock_price(symbol: str = "AAPL") -> str:
1616
"""
1717
>>> stock_price("EEEE")
18-
'No <fin-streamer> tag with the specified data-test attribute found.'
18+
'- '
1919
>>> isinstance(float(stock_price("GOOG")),float)
2020
True
2121
"""
@@ -24,12 +24,10 @@ def stock_price(symbol: str = "AAPL") -> str:
2424
url, headers={"USER-AGENT": "Mozilla/5.0"}, timeout=10
2525
).text
2626
soup = BeautifulSoup(yahoo_finance_source, "html.parser")
27-
specific_fin_streamer_tag = soup.find("fin-streamer", {"data-testid": "qsp-price"})
2827

29-
if specific_fin_streamer_tag:
30-
text = specific_fin_streamer_tag.get_text()
31-
return text
32-
return "No <fin-streamer> tag with the specified data-test attribute found."
28+
if specific_fin_streamer_tag := soup.find("span", {"data-testid": "qsp-price"}):
29+
return specific_fin_streamer_tag.get_text()
30+
return "No <fin-streamer> tag with the specified data-testid attribute found."
3331

3432

3533
# Search for the symbol at https://finance.yahoo.com/lookup

0 commit comments

Comments
 (0)