1

Im trying to download some reports from web page, using selenium and python

when i click on download link firefox shows save/open dialog

I have used firefox profile configuration as follows

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.panel.shown", False)
profile.set_preference("browser.helperApps.neverAsk.openFile", "application/pdf,attachment/pdf")
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf,attachment/pdf")
profile.set_preference("browser.download.dir", "c:\\firefox_downloads\\")

self.browser = webdriver.Firefox(profile)

but still it shows message box,

i have changed

self.browser = webdriver.Firefox(firefox_profile=profile)

like above but no chance >

Can any one help me to resolve this?

1 Answer 1

1

I have a little helper function which works for me.

It uses chromedriver though.

def driver_download(location_for_download):
    # options = Options()
    # options.headless = True
    chrome_options = webdriver.ChromeOptions()
    prefs = {'download.default_directory': location_for_download}
    chrome_options.add_experimental_option('prefs', prefs)
    # driver = webdriver.Chrome(chrome_options=chrome_options)
    driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver", chrome_options=chrome_options)
    return driver

Note: For my particular application, I was unable to use the headless. But it should work if its a direct link to the file.

Sign up to request clarification or add additional context in comments.

2 Comments

havent you used firefox?
@Roshan no, I have tried firefox and it is my preferred browser but for scraping and all I find chrome easier to work with.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.