在使用Selenium的下拉菜单中选择选项后,更新数据的问题

我正在尝试从网站获取数据库,该页面按月显示此信息。特别是通过一个下拉菜单,可以在其中选择月份和年份,并且使用选择的选项来更新此字段下的所有数据。

我正在使用Selenium来选择选项,但是问题是它出现在所选选项的相关字段中。但是,数据不会更新。 一旦选择了该选项,是否需要任何单击或其他功能来获得此更新的日期?

我正在使用Python,Selenium和代码中的网页。 选择了e选项,但此方法不起作用。

我正在使用python,selenium和代码第一部分中显示的所有库

代码在这里:

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],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()

zijijie 回答:在使用Selenium的下拉菜单中选择选项后,更新数据的问题

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3156005.html

大家都在问