So I have an script that check stock prices. Yahoo change something and now I get the % change rather than the stock price. Below is the original script. When I run it, I get "+0.70 (+0.03%)", rather than 2,477.83. The only difference I really see is:
data-reactid="36"
and
data-reactid="35".
When I change to 35, it fails. 36 works but only show % change. I want stock price, not % change.
thanks for your help!
import urllib.request
from bs4 import BeautifulSoup
# S&P 500
page = urllib.request.urlopen("https://finance.yahoo.com/quote/%5EGSPC?p=^GSPC")
content = page.read().decode('utf-8')
soup = BeautifulSoup(content, 'html.parser')
valsp = soup.find("span", {"data-reactid": "36"}).decode_contents(formatter="html")
print(valsp)