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.find_element_by_css_selector(f'input[type="search"]').send_keys('informe mensal')

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


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)
  • the xpath(...) should be for what element? 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 Mar 31, 2020 at 20:39

Your Answer

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

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