Define download directory for chromedriver selenium with python

前端 未结 3 2004
[愿得一人]
[愿得一人] 2021-02-04 15:54

Everything is in the title!

Is there a way to define the download directory for selenium-chromedriver used with python?

In spite of many research, I haven\'t fou

3条回答
  •  失恋的感觉
    2021-02-04 16:42

    I have faced recently the same issue. Tried a lot of solutions found in the Internet, no one helped. So finally I came to this:

    • Launch chrome with empty user-data-dir (in /tmp folder) to let chrome initialize it
    • Quit chrome
    • Modify Default/Preferences in newly created user-data-dir, add those fields to the root object (just an example):

      "download": { "default_directory": "/tmp/tmpX7EADC.downloads", "directory_upgrade": true }

    • Launch chrome again with the same user-data-dir

    Now it works just fine.

    Another tip: If you don't know file name of file that is going to be downloaded, create snapshot (list of files) of downloads directory, then download the file and find its name by comparin snapshot and current list of files in the downloads directory.

提交回复
热议问题