簡體   English   中英

使用python下載時如何將文件保存在當前磁盤中?

[英]How to save the file in the current disk when downloading using python?

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行通知:下載時文件不安全。 我刪除了這兩行。 它無法保存在我想要的磁盤中。

我該如何解決這個問題?

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個偏好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM