python selenium下载窗口_selenium指定目录下载文件且阻止浏览器弹框

selenium指定目录下载文件且阻止浏览器弹框该如何配置呢?

网上绝大部分的帖子的配置都是不起作用的。目前用的谷歌浏览器80版本的,经过测试以下方式完全可以实现该功能。只把核心代码展示下

start_time = time.time()

today = time.strftime('%Y-%m-%d', time.localtime(start_time))

save_path = r"E:下载-账户{0}".format(today) # 指定下载保存位置

# 记录失败

f = open('export_fail_zhanghu{0}.txt'.format(today),'w',encoding='utf-8')

start,end = get_dates('date.txt')

city_urls = get_city_urls('city_id_url_zhanghu.txt',start,end)

cookie = get_cookie('cookie.txt')

Options = Options()

# Options.add_argument("--headless")

Options.add_experimental_option("prefs", {

"download.default_directory": save_path,

"download.prompt_for_download": False, # 不弹框

})

driver = webdriver.Chrome(chrome_options=Options)

driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')

params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath':save_path}}

command_result = driver.execute("send_command", params)

run()

f.flush()

f.close()

end_time = time.time()

print('耗时{0}min'.format((end_time-start_time)/60))

selenium指定目录下载文件且阻止浏览器弹框配置如上,请放心使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值