配置下載文件路徑
配置方法是添加download.default_directory
,如:文章來源:http://www.zghlxwxcb.cn/news/detail-582149.html
option = webdriver.ChromeOptions()
prefs = {
'download.default_directory': r"E:\xxxx\xxxx", # 設置默認下載路徑
"profile.default_content_setting_values.automatic_downloads": 1 # 允許多文件下載
}
option.add_experimental_option("prefs", prefs)
webdriver.Chrome(chrome_options=option)
無界面瀏覽器設置路徑
對于無界面瀏覽器,為了安全,默認是不允許在無界面下進行下載文件到本地的操作的,但是可以通過配置進行修改,詳細請參考:https://stackoverflow.com/questions/45631715/downloading-with-chrome-headless-and-selenium文章來源地址http://www.zghlxwxcb.cn/news/detail-582149.html
option = webdriver.ChromeOptions()
option.add_argument("--incognito") # 配置隱私模式
option.add_argument("--headless=new")
prefs = {
"profile.managed_default_content_settings.images": 2, # 禁止加載圖片
'download.default_directory': r"E:\xxxx\xxxx", # 設置默認下載路徑
"profile.default_content_setting_values.automatic_downloads": 1 # 允許多文件下載
}
option.add_experimental_option("prefs", prefs)
到了這里,關于selenium設置(有界面/無界面瀏覽器)下載文件路徑的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!