【问题标题】:How to save the file in the current disk when downloading using python?使用python下载时如何将文件保存在当前磁盘中?
【发布时间】:2019-11-19 15:50:35
【问题描述】:
chrome_options = webdriver.ChromeOptions()

# Set preferences
prefsNotifications = {"profile.default_content_setting_values.notifications" : 2} 
prefsPopups = {"profile.default_content_settings.popups": 0}
prefsDownload = {"download.default_directory": CurDir}
prefsSafe = {'safebrowsing.enabled': 'false'}
chrome_options.add_experimental_option("prefs", prefsNotifications)
chrome_options.add_experimental_option("prefs", prefsPopups)
chrome_options.add_experimental_option("prefs", prefsDownload)
chrome_options.add_experimental_option("prefs", prefsSafe)

driver = webdriver.Chrome(CurDir+"\\chromedriver.exe", chrome_options=chrome_options)
driver.maximize_window()  
return driver

第 5 行和第 9 行,通知:下载时文件不安全。我删除了这两行。它无法保存在我想要的磁盘中。

我该如何解决这个问题?

【问题讨论】:

  • 当你使用第 5 行和第 9 行时,你能保存在想要的磁盘中吗?然后使用它们。

标签: python python-3.x web-scraping rpa


【解决方案1】:
def OpenBrowser():
    chromeOptions = webdriver.ChromeOptions()
    prefs = {"download.default_directory" : CurDir,"safebrowsing.enabled": "false","profile.default_content_setting_values.notifications" : 2, "profile.default_content_settings.popups": 0}
    chromeOptions.add_experimental_option("prefs",prefs)
    driver = webdriver.Chrome(executable_path = CurDir+"\\chromedriver.exe", chrome_options = chromeOptions)
    driver.maximize_window()
    return driver

功能通过 selenium 打开 chromedriver.exe,没有通知、警告或弹出窗口。 1个偏好。

【讨论】:

    猜你喜欢
    • 2020-09-21
    • 2010-09-10
    • 2013-11-05
    • 2020-12-17
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多