File tree 1 file changed +5
-5
lines changed
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
3
2
from bs4 import BeautifulSoup
4
- from requests import get
5
3
6
4
"""
7
5
Get the HTML code of finance yahoo and select the current qsp-price
@@ -22,11 +20,11 @@ def stock_price(symbol: str = "AAPL") -> str:
22
20
True
23
21
"""
24
22
url = f"https://finance.yahoo.com/quote/{ symbol } ?p={ symbol } "
25
- yahoo_finance_source = get (
23
+ yahoo_finance_source = requests . get (
26
24
url , headers = {"USER-AGENT" : "Mozilla/5.0" }, timeout = 10
27
25
).text
28
26
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" })
30
28
31
29
if specific_fin_streamer_tag :
32
30
text = specific_fin_streamer_tag .get_text ()
@@ -36,6 +34,8 @@ def stock_price(symbol: str = "AAPL") -> str:
36
34
37
35
# Search for the symbol at https://finance.yahoo.com/lookup
38
36
if __name__ == "__main__" :
37
+ from doctest import testmod
39
38
testmod ()
39
+
40
40
for symbol in "AAPL AMZN IBM GOOG MSFT ORCL" .split ():
41
41
print (f"Current { symbol :<4} stock price is { stock_price (symbol ):>8} " )
You can’t perform that action at this time.
0 commit comments