【问题标题】:Download .csr file automatically with selenium and python使用 selenium 和 python 自动下载 .csr 文件
【发布时间】:2020-07-06 18:49:53
【问题描述】:

伙计们,

我在使用 selenium 自动下载 .csr 文件时遇到了一个小问题。

我的网络驱动程序看起来像:

    def _set_preferences_for_download(download_dir, profile):
        profile.set_preference('browser.download.folderList',
                               CustomWebdriver.CUSTOM_LOCATION)
        profile.set_preference('browser.download.manager.showWhenStarting', False)
        profile.set_preference('browser.download.dir', download_dir)
        profile.set_preference("browser.helperApps.alwaysAsk.force", False)
        profile.set_preference("browser.download.manager.alertOnEXEOpen", False)
        profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream, "
                                                                         "application/xml, text/xml, "
                                                                         "text/plain, "
                                                                         "application/x-java-jnlp-file, "
                                                                         "application/vnd.ms-excel, "
                                                                         "application/pkcs8, "
                                                                         "application/pkcs10, "
                                                                         "application/pkix-cert, "
                                                                         "application/pkix-crl, "
                                                                         "application/pkcs7-mime, "
                                                                         "application/x-x509-ca-cert, "
                                                                         "application/x-x509-user-cert, "
                                                                         "application/x-pkcs7-crl, "
                                                                         "application/x-pem-file, "
                                                                         "application/x-pkcs12, "
                                                                         "application/x-pkcs7-certificates, "
                                                                         "application/x-pkcs7-certreqresp")
        profile.set_preference("browser.download.manager.focusWhenStarting", False)
        profile.set_preference("browser.download.useDownloadDir", True)
        profile.set_preference("browser.download.manager.closeWhenDone", True)
        profile.set_preference("browser.download.manager.showAlertOnComplete", False)
        profile.set_preference("browser.download.manager.useWindow", False)
        profile.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False)
        profile.set_preference("pdfjs.disabled", True)
        profile.set_preference("accessibility.blockautorefresh", False)
        return profile

我仍然面临:

你有什么想法吗?

【问题讨论】:

  • .csr 的应用程序类型是什么?检查 devtools 网络选项卡以获取此信息。
  • .csr 是 MIME 之后的证书签名请求,它是 application/pkcs10 pki-tutorial.readthedocs.io/en/latest/mime.html
  • 顺便说一句,您可以在文件名下方找到此信息:which is: PKCS#10 Certificate Request (928 bytes)
  • chrome 默认不会提示...可能需要为此使用 chromedriver。
  • 你能添加你的完整代码吗,就像你给的缝一样

标签: python selenium firefox webdriver csr


【解决方案1】:

this 代码为例(因为我不知道你是否已经这样做了) 您是否使用刚刚设置的首选项启动了 Firefox?

browser = webdriver.Firefox() 更改为browser = webdriver.Firefox(firefox_profile=YOURPROFILE HERE)

这是 Reddit 用户用来让 firefox 自动将文件保存到磁盘的完整代码:

# Set Firefox preferences so that the file automatically saves to disk when downloaded

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.preferences.instantApply",True)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain, application/octet-stream, application/binary, text/csv, application/csv, application/excel, text/comma-separated-values, text/xml, application/xml")
fp.set_preference("browser.helperApps.alwaysAsk.force",False)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.folderList",0)

# Open a browser and log in

browser = webdriver.Firefox(firefox_profile=fp)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 2021-11-16
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    相关资源
    最近更新 更多