Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98939

Problem with updating data after a option was selected in a dropmenu with Selenium

$
0
0

I am trying to obtain a database from a website, the page shows this information by months. Specifically by a dropmenu, where one can choose the month and year, and all data below this field is updated with the option choosed.

I am using Selenium for choosing an option, but the problem is that it appears in the related field the option choosed. however, the data is not updated. Is it neccesary any click or another function to achieve this updated date once the option was selected?

I am using Python, Selenium, and the webpage that is in the code. e option choosed, but this in not working.

I am using python, selenium and all the libraries that are showed in the first part of the code

The code is here:

import numpy as np
import io
import pandas as pd
import matplotlib.pyplot as plt
import datetime as dt
from sklearn import datasets, linear_model
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys

a=[]
b=[]
url="https://www.integra.com.pe/wps/portal/integra/personas/inversiones-y-rentabilidad/valor-cuota/consulta-el-valor-cuota"
# Start webdriver with Chrome
browser = webdriver.Chrome(executable_path=r"D:\python\afp\driver\chromedriver.exe")
browser.get(url)

lista_menu = browser.find_element_by_class_name('select')
drp=Select(lista_menu)

#This loop is for obtain all the options for the dropmenu
for option in drp.options:
    a=option.get_attribute("value")
    b.append(a)

print(b)
browser.close()

#This is for begin another web browser, i am doing this because I obtain errors otherwise

browser = webdriver.Chrome(executable_path=r"D:\python\afp\driver\chromedriver.exe")
browser.get(url)
lista_menu = browser.find_element_by_class_name('select')
drp=Select(lista_menu)
#browser.find_element_by_class_name('icon-inner').click()
lista_menu = browser.find_element_by_class_name('select')
drp=Select(lista_menu)
drp.select_by_value("201905")

#This loop is to obtain data considering all the values obtained in the first loop, however the problem is that the field change
# the value but the data, all the rows below mantain the same information

for month in b:
    browser = webdriver.Chrome(executable_path=r"D:\python\afp\driver\chromedriver.exe")
    browser.get(url)
    lista_menu = browser.find_element_by_class_name('select')
    drp=Select(lista_menu)
    drp.select_by_value(month)
    element = browser.find_element_by_class_name('table-4').text
    print(element)
    df = pd.read_fwf(io.StringIO(element),head=None, widths=[11, 12, 12, 12, 12], names=['Fecha', 'Fondo0', 'Fondo1', 'Fondo2', 'Fondo3'])
    df = df.drop([0], axis=0)
    df['Fecha'] = pd.to_datetime(df['Fecha'], format="%d/%m/%Y")
    print(df)

df['Fecha'] = df['Fecha'].map(dt.datetime.toordinal)
Fecha=df.iloc[:,0].values.reshape(-1,1)
print(Fecha)
Fondo3=df.iloc[:,4].values.reshape(-1,1)
print(Fondo3)

regr = linear_model.LinearRegression()
regr.fit(Fecha, Fondo3)

y_pred = regr.predict(Fecha)

print(regr.coef_)
print(regr.intercept_)

plt.scatter(Fecha, Fondo3)
plt.plot(Fecha, y_pred, color='red')
plt.show()


Viewing all articles
Browse latest Browse all 98939

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>