我正在尝试遍历一个表并下载xml文件,但是,我只下载了表中第一个元素的内容。如何才能正确地迭代以从每行下载内容?
我应该在for row in table:之后的哪里包含row才能正确地初始化?
from selenium import webdriver
options.add_argument("--incognito")
driver = webdriver.Chrome(options=options)
driver.get('https://fnet.bmfbovespa.com.br/fnet/publico/abrirGerenciadorDocumentosCVM?cnpjFundo=30983020000190')
driver.find_element_by_css_selector(f'input[type="search"]').click()
driver.find_element_by_css_selector(f'input[type="search"]').send_keys('rendimentos')
time.sleep(1)
table = driver.find_elements_by_xpath("//table[@id='tblDocumentosEnviados']//tr")
for row in table:
try:
WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH,"//table[@id='tblDocumentosEnviados']//td[text()='Rendimentos e Amortizações']/following-sibling::td[.//span[text()='Ativo']]/following-sibling::td//a[@title='Download do Documento']"))).click()
x = x + 1
print(x)
except:
print('except')编辑
我需要在这一行中添加行迭代才能成功:
try:
WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH,
"//table[@id='tblDocumentosEnviados']//td[text()='Rendimentos e Amortizações']/following-sibling::td[.//span[text()='Ativo']]/following-sibling::td//a[@title='Download do Documento']"))).click()发布于 2020-05-09 04:49:31
尝试下面的代码,这将指向您要查找的行。
options.add_argument("--incognito")
driver = webdriver.Chrome(options=options)
driver.get('https://fnet.bmfbovespa.com.br/fnet/publico/abrirGerenciadorDocumentosCVM?cnpjFundo=30983020000190')
driver.find_element_by_css_selector('input[type="search"]').click()
driver.find_element_by_css_selector('input[type="search"]').send_keys('rendimentos')
time.sleep(1)
table = driver.find_elements_by_xpath("//table[@id='tblDocumentosEnviados']//tr")
print(len(table))
for row in range(len(table)):
try:
WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH,"//table[@id='tblDocumentosEnviados']//tr[" + str(row) + "]//td[text()='Rendimentos e Amortizações']/following-sibling::td[.//span[text()='Ativo']]/following-sibling::td//a[@title='Download do Documento']"))).click()
x = row + 1
print(x)
except:
print('except')https://stackoverflow.com/questions/61686680
复制相似问题