valor indice
This commit is contained in:
@ -217,14 +217,16 @@ def search_indice(indice):
|
|||||||
soup = BeautifulSoup(response.content, 'html.parser')
|
soup = BeautifulSoup(response.content, 'html.parser')
|
||||||
|
|
||||||
# Buscar los valores dentro del HTML
|
# Buscar los valores dentro del HTML
|
||||||
|
chart_inner_title = soup.find("span", {"data-test": "chart-inner-title"})
|
||||||
price = soup.find("div", {"data-test": "instrument-price-last"})
|
price = soup.find("div", {"data-test": "instrument-price-last"})
|
||||||
price_change = soup.find("span", {"data-test": "instrument-price-change"})
|
price_change = soup.find("span", {"data-test": "instrument-price-change"})
|
||||||
price_change_percent = soup.find("span", {"data-test": "instrument-price-change-percent"})
|
price_change_percent = soup.find("span", {"data-test": "instrument-price-change-percent"})
|
||||||
porcentaje = price_change_percent.text.strip().replace("(", "").replace(")", "").replace("%", "")
|
porcentaje = price_change_percent.text.strip().replace("(", "").replace(")", "").replace("%", "")
|
||||||
|
indice_real = chart_inner_title.text.strip() if chart_inner_title else indice
|
||||||
|
|
||||||
if price and price_change and price_change_percent:
|
if price and price_change and price_change_percent:
|
||||||
data = {
|
data = {
|
||||||
"indice": indice,
|
"indice": indice_real,
|
||||||
"valorActual": price.text.replace(",", "").strip(), # Convertir a número
|
"valorActual": price.text.replace(",", "").strip(), # Convertir a número
|
||||||
"cambio": price_change.text.replace(",", "").strip(), # Convertir a número
|
"cambio": price_change.text.replace(",", "").strip(), # Convertir a número
|
||||||
"porcentaje": porcentaje # Eliminar paréntesis
|
"porcentaje": porcentaje # Eliminar paréntesis
|
||||||
|
Reference in New Issue
Block a user