Мне нужно собрать данные для более чем 2000 тикеров, используя данные, которые можно найти на этой странице: https://finance.yahoo.com/quote/AAPL. Мне удалось получить код объема, цены предложения и т. д., но мне не удалось получить тикер, текущую цену, процентное изменение и изменение.
Я проверил структуру html и в настоящее время имею этот код, но в итоге не получил нужных мне данных (все было NA). Я не совсем понимаю, как еще подойти к анализу html-структуры и как выбрать правильные части, чтобы получить то, что мне нужно. Я был бы очень признателен за понимание. Спасибо!
import requests
from bs4 import BeautifulSoup
# Define the URL
`url = 'https://finance.yahoo.com/quote/AAPL'
# Send a GET request to the URL
response = requests.get(url)
# Parse the HTML content
soup = BeautifulSoup(response.content, 'html.parser')
# Extract the price
price_element = soup.find('div', {'data-field': 'regularMarketPrice'})
price = price_element.text.strip() if price_element else 'N/A'
# Extract the live price
live_price_element = soup.find('fin-streamer', {'data-testid': 'qsp-price'})
live_price = live_price_element.text.strip() if live_price_element else 'N/A'
# Extract the change
change_element = soup.find('fin-streamer', {'data-field': 'regularMarketChange'})
change = change_element.text.strip() if change_element else 'N/A'
# Extract the change percent
percent_element = soup.find('fin-streamer', {'data-field': 'regularMarketChangePercent'})
percent_change = percent_element.text.strip() if percent_element else 'N/A'
# Print the extracted data
print('Price:', price)
print('Live Price:', live_price)
print('Change:', change)
print('Percent Change:', percent_change)
Подробнее здесь: https://stackoverflow.com/questions/766 ... m-yahoo-fi