File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 1- from doctest import testmod
2-
1+ import requests
32from bs4 import BeautifulSoup
4- from requests import get
53
64"""
75Get 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
3836if __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} " )
You can’t perform that action at this time.
0 commit comments