skip to Main Content

GOAL

  • not to get the error (both code snippet generates the same error)
  • it is running on an aws ec2 ubuntu
  • importing this for web scraping with python, selenium, beautifulsoup as continuously loading JS webpage
  • I follow this guide L

MY CODE

# selenium 3
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

ERROR

[WDM] - ====== WebDriver manager ======
2022-07-11 15:49:01,250 INFO ====== WebDriver manager ======
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-18-0987a487086c> in <module>
      2 from webdriver_manager.chrome import ChromeDriverManager
      3 
----> 4 driver = webdriver.Chrome(ChromeDriverManager().install())

~/.local/lib/python3.8/site-packages/webdriver_manager/chrome.py in install(self)
     36 
     37     def install(self) -> str:
---> 38         driver_path = self._get_driver_path(self.driver)
     39         os.chmod(driver_path, 0o755)
     40         return driver_path

~/.local/lib/python3.8/site-packages/webdriver_manager/core/manager.py in _get_driver_path(self, driver)
     27 
     28     def _get_driver_path(self, driver):
---> 29         binary_path = self.driver_cache.find_driver(driver)
     30         if binary_path:
     31             return binary_path

~/.local/lib/python3.8/site-packages/webdriver_manager/core/driver_cache.py in find_driver(self, driver)
     93         os_type = driver.get_os_type()
     94         driver_name = driver.get_name()
---> 95         driver_version = driver.get_version()
     96         browser_version = driver.browser_version
     97 

~/.local/lib/python3.8/site-packages/webdriver_manager/core/driver.py in get_version(self)
     41     def get_version(self):
     42         self._version = (
---> 43             self.get_latest_release_version()
     44             if self._version == "latest"
     45             else self._version

~/.local/lib/python3.8/site-packages/webdriver_manager/drivers/chrome.py in get_latest_release_version(self)
     35 
     36     def get_latest_release_version(self):
---> 37         self.browser_version = get_browser_version_from_os(self.chrome_type)
     38         log(f"Get LATEST {self._name} version for {self.browser_version} {self.chrome_type}")
     39         latest_release_url = (

~/.local/lib/python3.8/site-packages/webdriver_manager/core/utils.py in get_browser_version_from_os(browser_type)
    150         return get_browser_version(browser_type, metadata)
    151 
--> 152     cmd_mapping = {
    153         ChromeType.BRAVE: {
    154             OSType.LINUX: linux_browser_apps_to_cmd(

KeyError: 'google-chrome'

Tried to solve by

2

Answers


  1. Chosen as BEST ANSWER

    Ubuntu 22.04 Chromium Browser installation LINK

    TERMINAL COMAMNDS:

    sudo apt update
    sudo apt install chromium-browser
    

    test

    chromium-browser
    

    How to Setup Selenium with ChromeDriver on Ubuntu 20.04 & 18.04 LINK

    TERMINAL COMMANDS:

    sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add 
    sudo bash -c "echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google-chrome.list" 
    sudo apt -y update 
    sudo apt -y install google-chrome-stable 
    

    Check version

    google-chrome --version 
    
    wget https://chromedriver.storage.googleapis.com/94.0.4606.61/chromedriver_linux64.zip 
    unzip chromedriver_linux64.zip 
    
    sudo mv chromedriver /usr/bin/chromedriver 
    sudo chown root:root /usr/bin/chromedriver 
    sudo chmod +x /usr/bin/chromedriver 
    

  2. It may be a Selenium 4 error?

    Try this code to see if it works

    # selenium 4
    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service as ChromeService
    from webdriver_manager.chrome import ChromeDriverManager
    
    driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search