1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Issue with downloading files using seleniumbase

Discussão em 'Python' iniciado por Stack, Setembro 28, 2024 às 12:02.

  1. Stack

    Stack Membro Participativo

    I have been trying to build a script to automate the download of a statistics file.

    The site is JS heavy and there is no link readily available. I have been able to build a script that executes the necessary steps, but I am struggling to actually successfully download the file. Any tips on how I can ensure that the file is actually downloaded before closing down the browser?

    from seleniumbase import Driver

    downloads_folder = "\\downloads"
    driver = Driver(browser="chrome")
    driver.execute_cdp_cmd("Page.setDownloadBehavior", {"behavior": "allow", "downloadPath": downloads_folder})
    username = "xxxxx"
    password = "xxxxx"

    try:
    driver.open("https://new.stamdata.com/app/statistics")
    driver.click('button:contains("Account")')
    driver.click("div#app div div:nth-of-type(2) span p")
    driver.type('input[name="username"]', username)
    driver.type('input[name="password"]', password)
    driver.click('button:contains("sign in")')
    driver.assert_element('button:contains("Excel export (max 50 000 rows)")')
    driver.click('button:contains("Excel export (max 50 000 rows)")')
    # add wait for download

    driver.click('button:contains("menu")')
    driver.click("div#app div div:nth-of-type(3) span p")
    driver.click('button:contains("log out")')
    finally:
    driver.quit()


    I have tried various waits and timeouts, but nothing seems to work.

    Continue reading...

Compartilhe esta Página