1

I am trying to create a scrapper that enters a website and downloads an XML file containing a balance sheet from real estate funds.

With the code below, I enter a website for a specific fund with document number 07000400000146 (at the end of URL), filter the documents with a search bar on the website, and click to download the first document in the table using XPath.

driver.get('https://fnet.bmfbovespa.com.br/fnet/publico/abrirGerenciadorDocumentosCVM?cnpjFundo=07000400000146')
driver.find_element_by_css_selector(f'input[type="search"]').click()
driver.find_element_by_css_selector(f'input[type="search"]').send_keys('informe mensal')
time.sleep(1)
driver.find_element_by_xpath('//*[@id="tblDocumentosEnviados"]/tbody/tr[1]/td[10]/div/a[2]/i').click()

How can I improve this code to click on the download button only for documents with '02/2020' on the column "Data de Referência"?

1 Answer 1

2

You can use find_elements_by_xpath (note the s) to find all elements that match a search.

all_rows = driver.find_element_by_xpath('//*[@id="tblDocumentosEnviados"]/tbody/tr')

Then you can filter out the rows using:

rows_for_feb_2020 = [row for rows in all_rows if (put here a boolean expression to discover if a row is of 02/2020)]

Then you can click in each one:

map(lambda row: row.find_element_by_xpath(...).click(), rows_for_feb_2020)
2
  • the xpath(...) should be for what element? Commented Mar 31, 2020 at 20:33
  • And can you give me some clues to create the boolean expression you mentioned? This is new for me Commented Mar 31, 2020 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.