Disable firefox save as dialog-selenium

后端 未结 3 1519
日久生厌
日久生厌 2021-01-05 16:49

I am web scraping with selenium and whenever i try to download i file the firefox download/save as file pops up however, even If i apply profile.set_preference(\'brows

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 16:54

    you should do two things, first set these three preferences as follows (this is in Java but I guess you manage to translate that to python :-):

    profile.setPreference("browser.download.dir", "c:/yourDownloadDir");
    profile.setPreference("browser.download.folderList", 2);
    profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/csv, text/csv");
    

    secondly, you should make sure the download file has the desired mime type. To do that, you can use the web developer tools and inspect the download.

    EDIT:

    To find out the MIME type open Chrome, press Ctrl+Shift+I (Cmd+Alt+I on Mac OS) change to the 'Network' tab and click your download link. You should see something like this:

    Chrome developer tools mime type

提交回复
热议问题