【開発メモ】windowsタスクスケジューラでchromedriverを絡めたファイルを動かしたい

【開発メモ】windowsタスクスケジューラでchromedriverを絡めたファイルを動かしたい

C:>python test.py
Traceback (most recent call last):
  File "C:\Users\admin\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\admin\Anaconda3\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\admin\Anaconda3\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 指定されたファイルが見つかりません。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\\test.py", line 32, in <module>
    driver = webdriver.Chrome(executable_path='"./chromedriver.exe')
  File "C:\Users\admin\Anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\admin\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

やったこと

pip install chromedriver-binary==90.0.4430.93

PATHが違う?
Msysでは動作するがコマンドプロンプトだと動かない。

chromedriver-binary-autoをインストール

C:\Users\admin>pip install chromedriver-binary-auto
Collecting chromedriver-binary-auto
  Downloading https://files.pythonhosted.org/packages/cc/78/e3809d6fbe7cf1baa5405ec9c237b483ec1dbfdd2b56b6be6485cd83ac49/chromedriver-binary-auto-0.1.1.tar.gz
Building wheels for collected packages: chromedriver-binary-auto
  Building wheel for chromedriver-binary-auto (setup.py) ... done
  Created wheel for chromedriver-binary-auto: filename=chromedriver_binary_auto-0.1.1-cp37-none-any.whl size=5950645 sha256=002f9587d8f1fd56cca64eae5a553416ce2b25bd58da2b442d9703628b27da6d
  Stored in directory: C:\Users\admin\AppData\Local\pip\Cache\wheels\2f\3b\af\817110869a9adb0837c6b3551fba7c27a748082cfd9914d55d
Successfully built chromedriver-binary-auto
Installing collected packages: chromedriver-binary-auto
Successfully installed chromedriver-binary-auto-0.1.1

これでコマンドプロンプトで動くようになった。

下記のエラーは無視してOK

WebUSBでデバイスへの接続に問題がない場合は、これらの警告を無視しても問題はないようです。

C:\Users\admin\Desktop>python test02.py

DevTools listening on ws://127.0.0.1:58210/devtools/browser/e9ea4ac7-e841-461e-b91d-eda2d8aaa00a
[9120:11256:0501/141305.593:ERROR:device_event_log_impl.cc(214)] [14:13:05.593] USB: usb_device_handle_win.cc:1054 Failed to read descriptor from node connection: システムに接続されたデバイスが機能していません。 (0x1F)
[9120:11256:0501/141305.594:ERROR:device_event_log_impl.cc(214)] [14:13:05.594] USB: usb_device_handle_win.cc:1054 Failed to read descriptor from node connection: システムに接続されたデバイスが機能していません。 (0x1F)

C:\Users\admin\Desktop>python test02.py

DevTools listening on ws://127.0.0.1:58299/devtools/browser/3c3dd867-6b3b-4887-96cd-657a3841e267

参考サイト
https://laboratory.kazuuu.net/get-web-page-titles-in-python-using-selenium/

———- PR ———-