使用Selenium下载文件,pref download.prompt_for_download设置为False但仍然出现提示

问题描述 投票:0回答:1

今天我打算对之前已经实现的东西做一些修改,上次我维护它时它工作得很好。但是,当我在修改任何内容之前进行测试运行时,我意识到之前下载没有问题的文件开始引发错误,因为实际上没有下载任何内容。我认为是当我的 chrome 更新并且我更改了 chromeDriver 以匹配它时,下载开始出错。 我已经做了一些研究,因为我认为我的偏好可能是错误的或其他什么,但我所做的任何改变都没有帮助。

这些是我的实际偏好

 prefs = {
        'printing.print_preview_sticky_settings': json.dumps(settings),
        'download.default_directory': file_download_path,
        'savefile.default_directory': file_download_path,
        'profile.default_content_settings': {"images": 2},
        "download_restrictions": 0,
        "plugins.always_open_pdf_externally": True,
        'download.prompt_for_download': False,
        "safebrowsing.enabled": True,
        "profile.default_content_settings.popups": 0,
    }

以及 chromeOptions 的参数

if headless_mode:
        chrome_options.add_argument("--headless=new")
    chrome_options.add_argument('--disable-logging')
    chrome_options.add_argument("--no-sandbox")
    chrome_options.add_argument("--disable-dev-shm-usage")
    chrome_options.add_argument('--kiosk-printing')
    chrome_options.add_argument("window-size=1280,960")
    chrome_options.add_argument('--host-resolver-rules=MAP www.google-analytics.com 127.0.0.1')
    
    chrome_options.add_argument("--disable-blink-features")
    chrome_options.add_argument('--disable-blink-features=AutomationControlled')
    chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
    chrome_options.add_experimental_option('useAutomationExtension', False)
    chrome_options.add_argument("user-agent={}".format(user_agent))
    chrome_options.add_argument("--disable-gpu")

    chrome_options.add_argument('--incognito')

    chrome_options.add_experimental_option('prefs', prefs)
python web-scraping download selenium-chromedriver prompt
1个回答
0
投票

我正在浏览更多内容以寻找答案,并偶然发现了与我的类似的SKV问题,禁用隐身模式确实会使提示停止显示。我想要继续使用隐身模式,我们将不得不等待修复,但虽然它不会发生,但使用不带该选项的方法可以完成工作。

© www.soinside.com 2019 - 2024. All rights reserved.