小编Tyl*_*son的帖子

selenium、chromedriver_autoinstaller 和 pyinstaller 在一个文件中

我正在尝试使用 pyinstaller 创建一个 onefile .exe,它将利用 chromedriver_autoinstaller 以便 chromedriver 始终是最新的。该代码在 IDE 中运行时工作正常,但一旦我使用 pyinstaller 创建 .exe,它就会抛出“chrome_autoinstaller 的特定问题”消息。由于 chromedriver_autoinstaller 不起作用,因此程序无法找到 chromedriver。该程序确实可以通过直接引用 chromedriver 文件路径在没有自动安装程序的 .exe 中运行,但如果可能的话,我更愿意使用这个包。

class LoginPCC:
    def __init__(self):  # create an instance of this class. Begins by logging in
        try:
            chrome_options = webdriver.ChromeOptions()
            settings = {
                "recentDestinations": [{
                    "id": "Save as PDF",
                    "origin": "local",
                    "account": "",
                }],
                "selectedDestinationId": "Save as PDF",
                "version": 2
            }
            prefs = {'printing.print_preview_sticky_settings.appState': json.dumps(settings), 
            "plugins.always_open_pdf_externally": True}
            chrome_options.add_experimental_option('prefs', prefs)
            chrome_options.add_argument('--kiosk-printing')
            try:
                chromedriver_autoinstaller.install()
            except:
                print('Specific issue with chrome_autoinstaller')
            try:
                self.driver …
Run Code Online (Sandbox Code Playgroud)

python selenium pyinstaller selenium-chromedriver

2
推荐指数
1
解决办法
5263
查看次数