【问题标题】:How to download pdf files using selenium in python如何在 python 中使用 selenium 下载 pdf 文件
【发布时间】:2018-11-13 14:52:19
【问题描述】:

我正在尝试使用 selenium 从网站下载 pdf 文件,但我能够打开文件,但无法使用代码自动下载。

代码:

chrome_profile = webdriver.ChromeOptions()
profile = {"download.default_directory": "C:\Users\Downloads",
   "download.prompt_for_download": False,
   "download.directory_upgrade": True,
   "plugins.plugins_disabled": ["Chrome PDF Viewer"]}
chrome_profile.add_experimental_option("prefs", profile)

请提出建议。提前谢谢你

【问题讨论】:

  • 你用的是哪个浏览器?
  • @Prany,谷歌浏览器

标签: python python-2.7 google-chrome selenium


【解决方案1】:

这样问题就解决了:

prefs = {"plugins.always_open_pdf_externally": True}
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "\path\chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)

【讨论】:

    【解决方案2】:

    把它放在代码的配置文件部分,它会禁用 chrome PDF 查看器并触发自动下载

    "plugins.plugins_disabled": ["Chrome PDF Viewer"]
    

    【讨论】:

      猜你喜欢
      • 2017-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-12
      相关资源
      最近更新 更多