Downloading a file at a specified location through python and selenium using Chrome driver

后端 未结 8 1497
囚心锁ツ
囚心锁ツ 2020-12-01 02:56

I am trying to automatically download some links through selenium\'s click functionality and I am using a chrome webdriver and python as the programming lan

8条回答
  •  执笔经年
    2020-12-01 03:35

    If you are using linux distribution

    Use this code

    prefs = {'download.prompt_for_download': False,
             'download.directory_upgrade': True,
             'safebrowsing.enabled': False,
             'safebrowsing.disable_download_protection': True}
    
    options.add_argument('--headless')
    options.add_experimental_option('prefs', prefs)
    driver = webdriver.Chrome('chromedriver.exe', chrome_options=options)
    driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
    driver.desired_capabilities['browserName'] = 'ur mum'
    params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': r'C:\chickenbutt'}}
    driver.execute("send_command", params)
    

提交回复
热议问题