Define boot directory for chromidra sedan using python

Everything is in the title!

Is there a way to determine the boot directory for selenium-chromedriver used with python?

Despite numerous studies, I did not find anything convincing ... As a beginner, I saw a lot about the “desired features” or “options” for the Chromedriver, but nothing solved my problem ... (and I still don’t know is it!)

To explain a bit more of my problem: I have a lot of urls to crawl (200,000) and for each file url to download. I need to create a table with a url, the information that I broke on it, And the name of the file that I just downloaded for each web page. With the volume that I have to process, I created threads that open multiple instances of chrome plating to speed up processing. The problem is that each downloaded file goes to the same default directory, and I can no longer link the file to the URL ... So the idea is to create a download directory for each stream to manage them one at a time .

If someone has an answer to my question in the heading OR a workaround to identify the downloaded file and link it to the current URL, I will be grateful!

+7
source share
3 answers

For chromedriver1 create a new profile and inside this profile set download.default_directory to the right place and set this profile for chrome using chrome.profile . The selenium-chromedriver must have some methods for creating new profiles (at least with ruby), since they need special processing.

Chromedriver2 does not support profile customization. You can set preferences with it. If you want to set the download directory, here is how you do it:

 prefs: { download: { default_directory: "/tmp" } } 

Ruby selenium-webdriver does not yet support this function, however a python variant can do.

+1
source

I recently ran into the same issue. I tried many solutions found on the Internet, no one helped. So finally, I came to the following:

  • Run chrome with an empty user-data-dir directory (in the / tmp folder) so that chrome initializes it
  • Get out of chrome
  • Change the default settings / preferences in the newly created user-data-dir directory, add these fields to the root object (just an example):

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

  • Run chrome again using the same user data file

Now it works fine.

One more tip: if you do not know the file name of the file to be downloaded, create a snapshot (file list) of the download directory, then download the file and find its name by comparing the snapshot and the current list of files in the download directory.

+1
source

Please try the code below ....

 System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); String downloadFilepath = "/path/to/download"; HashMap<String, Object> chromePrefs = new HashMap<String, Object>(); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("download.default_directory", downloadFilepath); ChromeOptions options = new ChromeOptions(); HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>(); options.setExperimentalOptions("prefs", chromePrefs); options.addArguments("--test-type"); DesiredCapabilities cap = DesiredCapabilities.chrome(); cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); cap.setCapability(ChromeOptions.CAPABILITY, options); WebDriver driver = new ChromeDriver(cap); 
0
source

All Articles