Geckodriver Selenium Auto下载PDF [英] Geckodriver Selenium Auto Download PDFs

查看:58
本文介绍了Geckodriver Selenium Auto下载PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在geckodriver/Firefox中自动下载.pdf文件.我搜索了stackoverflow和其他资源,并认为下面的代码应该可以工作:

I'm trying to automatically download .pdf files in geckodriver/Firefox. I've searched on stackoverflow and other resources and think the code below should work:

profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", 'C:\\Users\\xyz\\Downloads\\')
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,application/pdf,application/x-pdf,application/vnd.pdf")
profile.set_preference("pref.downloads.disable_button.edit_actions", True)
profile.set_preference("browser.helperApps.neverAsk.openFile", "application/octet-stream,application/pdf,application/x-pdf,application/vnd.pdf")
browser = webdriver.Firefox(firefox_profile=profile)

我也尝试过:

profile.set_preference("pdfjs.disabled", True)

但是,Firefox不会自动下载.pdf(即使它是http请求中的application/pdf).另外,在Firefox中加载该配置文件后,在选项/应用程序"下,PDF格式仍显示在Firefox中预览",而不是保存文件" ...我在做什么错?

However, Firefox does not automatically download the .pdf (even though it is application/pdf in the http req). Also, after I load that profile in Firefox, under "Options / Applications", the PDF format still shows "Preview in Firefox" instead of "Save File"... What am I doing wrong?

推荐答案

请尝试在现有列表中添加以下首选项:

Try by adding the following preference also, to the existing list:

fp.setPreference("pdfjs.enabledCache.state", false);
fp.setPreference("browser.helperApps.neverAsk.openFile","application/pdf");

这篇关于Geckodriver Selenium Auto下载PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆