我为Mozilla使用了Scrapy + Selenium 3.141.0和geckodriver v0.24.0,当我请求下载文件并停止我的蜘蛛时,我无法关闭pop-UPS。 这是我要避免弹出窗口的代码
options = Options()
#options.headless = True
options.accept_untrusted_certs = True
fp = webdriver.FirefoxProfile()
path = "C:\\Test\\"
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.dir", path)
fp.set_preference("browser.download.manager.alertOnEXEOpen", False)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk",
"application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")
fp.set_preference("browser.download.manager.alertOnEXEOpen", False)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,text/plain")
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.manager.focusWhenStarting", False)
fp.set_preference("browser.download.useDownloadDir", True)
fp.set_preference("browser.helperApps.alwaysAsk.force", False)
fp.set_preference("browser.download.manager.alertOnEXEOpen", False)
fp.set_preference("browser.download.manager.closeWhenDone", True)
fp.set_preference("browser.download.manager.showAlertOnComplete", False)
fp.set_preference("browser.download.manager.useWindow", False)
fp.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False);
fp.set_preference("pdfjs.disabled", True)
self.driver = webdriver.Firefox(options=options,firefox_profile=fp)
请提示我不要这样做,通常我希望禁止在Mozilla中下载文件 感谢您的关注! 附言我尝试了其他答案中给出的解决方案没有帮助:(