- Joined
- Mar 31, 2023
- Messages
- 86
- Reaction score
- 4
Hello everyone,
I am currently facing a minor issue that I am unable to resolve. The problem is that my code is returning values that seem unrelated and I am unsure of the reason behind it.
I would greatly appreciate any help to resolve this matter.
Here's the code:
Phro0244.
I am currently facing a minor issue that I am unable to resolve. The problem is that my code is returning values that seem unrelated and I am unsure of the reason behind it.
I would greatly appreciate any help to resolve this matter.
Here's the code:
Python:
import requests
from bs4 import BeautifulSoup
com_list = ['AAPL']
symbol = com_list[0]
url = f'https://finance.yahoo.com/quote/{symbol}?p={symbol}&.tsrc=fin-srch'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
name = soup.find('h1', {'class': 'D(ib) Fz(18px)'}).text
print(name)
regularMarketPrice = soup.find('fin-streamer', {'class': 'Fw(b) Fz(36px) Mb(-4px) D(ib)','data-symbol':symbol,'data-test':'qsp-price','data-pricehint': '2', 'data-field': 'regularMarketPrice'})['value']
regularMarketPrice_ = float(regularMarketPrice)
regularMarketChange = soup.find('fin-streamer', {'class': 'Fw(500) Pstart(8px) Fz(24px)','data-symbol':symbol,'data-test':'qsp-price-change','data-field': 'regularMarketChange','data-trend':'txt','data-pricehint':'2'})['value']
regularMarketChange_ = float(regularMarketChange)
regularMarketChangePercent = soup.find('fin-streamer', {'class': 'Fw(500) Pstart(8px) Fz(24px)', 'data-field': 'regularMarketChangePercent'})['value']
regularMarketChangePercent_ = str(float(regularMarketChangePercent) * 100) + '%'
print(regularMarketPrice_, ':', str(regularMarketChange_) + '%', ':', regularMarketChangePercent_)
Phro0244.
Last edited: