ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.04k stars 1.09k forks source link

Custom Download Path Not Working with undetected_chrome #1935

Open babarali539 opened 6 days ago

babarali539 commented 6 days ago

I was previously using the default WebDriver from Selenium for web scraping, and I had set a custom download path that was working perfectly. However, after switching to undetected_chrome, the download files are now being saved to the default downloads directory instead of the custom path I specified.

Here is my method to initialize driver:

def initialize_driver(storage_directory):
    options = uc.ChromeOptions()
    options.add_argument('--headless=new')
    options.add_argument('--no-sandbox')

    prefs = {
        "download.default_directory": storage_directory,
        "download.prompt_for_download": False,
        "download.directory_upgrade": True,
        "safebrowsing.enabled": True,
        "profile.default_content_setting_values.automatic_downloads": 1
    }
    options.add_experimental_option("prefs", prefs)

    driver = uc.Chrome(options=options)
    return driver

And here is the method to set custom download path

def ensure_storage_directory():
    env = os.getenv('ENVIRONMENT', 'development')
    if env == 'production':
        storage_directory = "/tmp/storage"
    else:
        storage_subdirectory = 'storage'
        current_directory = os.getcwd()
        storage_directory = os.path.join(current_directory, storage_subdirectory)

    if not os.path.exists(storage_directory):
        os.makedirs(storage_directory)
    return storage_directory

Environment OS: ubuntu-22.04 Python Version: 3.10 undetected_chrome Version: 3.5.5

Any help or guidance on how to resolve this issue would be greatly appreciated. Thank you!

weyseley commented 3 days ago

i have the same problem