Automatic download file from web page

16,931

You can use selenium web driver to automate the downloading. You can use below snippet for browser download preferences in java.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir", "C:\\downloads");
profile.setPreference("browser.helperApps.neverAsk.openFile","text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,text/html,text/plain,application/msword,application/xml");

To handle the popup using this class when popup comes.

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_DOWN); 
robot.keyRelease(KeyEvent.VK_DOWN);
robot.keyPress(KeyEvent.VK_ENTER); 
robot.keyRelease(KeyEvent.VK_ENTER);
Share:
16,931
Steven
Author by

Steven

French Data Engineer. Used to live in Japan (JLPT N2) Expert in data processing (SQL - ETL - Big Data), data modeling and reporting Did I just fixed that problem you were searching for hours online ? Or I helped you with that urgent task your boss wanted to be solved ASAP ? Maybe I did a bit of your homework and you will have a nice grade tomorrow ? All that time you just saved so you can now spend it at the coffee machine, maybe we can share a coffee together ;-)

Updated on June 04, 2022

Comments

  • Steven
    Steven almost 2 years

    I am looking for a method to download automatically a file from a website.

    Currently the process is really manual and heavy. I go on a webpage, I enter my pass and login. It opens a pop up, where I have to click a download button to save a .zip file.

    Do you have any advice on how I could automate this task ?

    I am on windows 7, and I can use mainly MS dos batch, or python. But I am open to other ideas.