前提
以下のYouTubeにてWEBスクレイピングの勉強をしています。
https://www.youtube.com/watch?v=VRFfAeW30qE&lc=UgwlkYQ_IuC_Y11aIeB4AaABAg.9K8rGLlJNID9KGSMi2LGJd
しかし、ブラウザを立ち上げるコードを実行しようとすると、長文のエラーが出てきてしまい、躓いている状況です。
もし、以下のエラーがどういったもので、どうすれば解決するのかがわかる方がいらっしゃったらご教示いただきたいです。
発生している問題・エラーメッセージ
長文のエラーというのが以下になります。
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\driver_finder.py:38, in DriverFinder.get_path(service, options) 37 try: ---> 38 path = SeleniumManager().driver_location(options) if path is None else path 39 except Exception as err: File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\selenium_manager.py:79, in SeleniumManager.driver_location(self, options) 72 """Determines the path of the correct driver. 73 74 :Args: 75 - browser: which browser to get the driver path for. 76 :Returns: The driver path to use 77 """ ---> 79 browser = options.capabilities["browserName"] 81 args = [str(self.get_binary()), "--browser", browser] AttributeError: 'str' object has no attribute 'capabilities' During handling of the above exception, another exception occurred: AttributeError Traceback (most recent call last) Cell In[11], line 1 ----> 1 browser = webdriver.Chrome('chromedriver.exe') File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chrome\webdriver.py:45, in WebDriver.__init__(self, options, service, keep_alive) 42 service = service if service else Service() 43 options = options if options else Options() ---> 45 super().__init__( 46 DesiredCapabilities.CHROME["browserName"], 47 "goog", 48 options, 49 service, 50 keep_alive, 51 ) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chromium\webdriver.py:51, in ChromiumDriver.__init__(self, browser_name, vendor_prefix, options, service, keep_alive) 47 self.vendor_prefix = vendor_prefix 49 self.service = service ---> 51 self.service.path = DriverFinder.get_path(self.service, options) 53 self.service.start() 55 try: File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\driver_finder.py:40, in DriverFinder.get_path(service, options) 38 path = SeleniumManager().driver_location(options) if path is None else path 39 except Exception as err: ---> 40 msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager." 41 raise NoSuchDriverException(msg) from err 43 if path is None or not Path(path).is_file(): AttributeError: 'str' object has no attribute 'capabilities'
該当のソースコード
Python
1from selenium import webdriver 2from time import sleep 3browser = webdriver.Chrome('chromedriver.exe')
試したこと
動画内でWindowsでエラーが出た時の対策としてwebdriver_managerを使用する方法が紹介されていたのですが、こちらでも同様に長文のエラーが出てきました。
Python
1from webdriver_manager.chrome import ChromeDriverManager 2browser = webdriver.Chrome(ChromeDriverManager().install())
Python
1from webdriver_manager.chrome import ChromeDriverManager 2browser = webdriver.Chrome(ChromeDriverManager().install())
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\driver_finder.py:38, in DriverFinder.get_path(service, options) 37 try: ---> 38 path = SeleniumManager().driver_location(options) if path is None else path 39 except Exception as err: File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\selenium_manager.py:79, in SeleniumManager.driver_location(self, options) 72 """Determines the path of the correct driver. 73 74 :Args: 75 - browser: which browser to get the driver path for. 76 :Returns: The driver path to use 77 """ ---> 79 browser = options.capabilities["browserName"] 81 args = [str(self.get_binary()), "--browser", browser] AttributeError: 'str' object has no attribute 'capabilities' During handling of the above exception, another exception occurred: AttributeError Traceback (most recent call last) Cell In[12], line 1 ----> 1 browser = webdriver.Chrome(ChromeDriverManager().install()) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chrome\webdriver.py:45, in WebDriver.__init__(self, options, service, keep_alive) 42 service = service if service else Service() 43 options = options if options else Options() ---> 45 super().__init__( 46 DesiredCapabilities.CHROME["browserName"], 47 "goog", 48 options, 49 service, 50 keep_alive, 51 ) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chromium\webdriver.py:51, in ChromiumDriver.__init__(self, browser_name, vendor_prefix, options, service, keep_alive) 47 self.vendor_prefix = vendor_prefix 49 self.service = service ---> 51 self.service.path = DriverFinder.get_path(self.service, options) 53 self.service.start() 55 try: File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\driver_finder.py:40, in DriverFinder.get_path(service, options) 38 path = SeleniumManager().driver_location(options) if path is None else path 39 except Exception as err: ---> 40 msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager." 41 raise NoSuchDriverException(msg) from err 43 if path is None or not Path(path).is_file(): AttributeError: 'str' object has no attribute 'capabilities'
補足情報(FW/ツールのバージョンなど)
Windows 11 Home
Python 3.12.0
Google Chrome バージョン: 118.0.5993.89(Official Build) (64 ビット)

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/10/23 14:29