6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ChromeDriverManagerで【OSError】が出た件

Posted at

はじめに

seleniumを使用したプログラムでエラーが発生しました。
とりあえずエラーは消えたので、備忘録として記事に残します。

解決にあたり、下記記事を参考にさせていただきました。
ありがとうございました。

内容

exe化し、常時動かしていたプログラムを少し内容変更した際にエラーが発生してしまいました。
そこでエラー文を見てみるとWebDriver周りでエラーが出ていることがわかりました。

エラー文一部抜粋

  File "xxxxx", line 250, in xxxxxx
    driver = webdriver.Chrome(service=service, options=options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
             
OSError: [WinError 193] %1 は有効な Win32 アプリケーションではありません。

中身のコード

        service = Service(ChromeDriverManager().install())
        options = webdriver.ChromeOptions()
        options.add_argument('--start-maximized')
        options.add_experimental_option('prefs', profile)
        driver = webdriver.Chrome(service=service, options=options)
        driver.get(URL)

開発時、Chrome側のバージョンを気にするのが面倒だったので、自動でドライバをダウンロードしてくれるwebdriver_managerを使用していました。
当初はエラーもなく動いてくれていたので、これでプログラムを組んでいました。

そこで参考記事を確認してみると

Selenium 4.6から、Selenium自体にChromeDriver自動更新機能「Selenium Manager」が搭載されたことで、このシンプルな記述だけで済むようなりました。

と書かれており、serviceの記述がもう必要ないことがわかったので、
下記のようにコードを書き換えました。

        options = webdriver.ChromeOptions()
        options.add_argument('--start-maximized')
        options.add_experimental_option('prefs', profile)
        driver = webdriver.Chrome(options=options)
        driver.get(URL)

この書き換えにより、問題なく処理が走りました。

終わりに

exe化やスクレイピングは便利ですが、正しく知識をつけないとたびたびエラーになるイメージがあります。
私自身これからも精進します。

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?