Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing ChromeDriver and Headless Chrome Driver with latest version of Selenium #351

Open
aleksandar-devedzic opened this issue Mar 15, 2024 · 2 comments

Comments

@aleksandar-devedzic
Copy link

aleksandar-devedzic commented Mar 15, 2024

I am using Python and Selenium on AWS Lambdas for crawling. I have updated Python to 3.11 and Selenium to 4.18.0, but then my crawlers stopped working. This is the code for Selenium:


import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

def get_headless_driver():
    options = Options()
    service = Service(executable_path=r'/opt/chromedriver')
    options.binary_location = '/opt/headless-chromium'
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--single-process')
    options.add_argument('--disable-dev-shm-usage')
    options.add_argument('--window-size=1920x1080')
    options.add_argument('--start-maximized')

    return webdriver.Chrome(service=service, options=options)

def get_selenium_driver():
    return get_local_driver() if os.environ.get('STAGE') == 'local' else get_headless_driver()

This is the code for installing chrome driver:


#! /bin/bash

# exit when any command fails
set -e

NOCOLOR='\033[0m'
GREEN='\033[0;32m'

echo -e "\n${GREEN}Installing 'headless' layer dependencies...${NOCOLOR}\n"
sudo mkdir -p layers/headless && sudo chmod 777 layers/headless && cd layers/headless

# https://github.com/adieuadieu/serverless-chrome/issues/133
echo -e "\n${GREEN}Installing Chrome Driver v2.37...${NOCOLOR}\n"
sudo curl -SL https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip > chromedriver.zip
sudo chmod 755 chromedriver.zip
sudo unzip chromedriver.zip
sudo rm chromedriver.zip

echo -e "\n${GREEN}Installing Serverless Chrome v1.0.0-37...${NOCOLOR}\n"
sudo curl -SL https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-41/stable-headless-chromium-amazonlinux-2017-03.zip > headless-chromium.zip
sudo chmod 755 headless-chromium.zip
sudo unzip headless-chromium.zip
sudo rm headless-chromium.zip

cd ../../

I am getting this error:

Message: Service /opt/chromedriver unexpectedly exited. Status code was: 127

How should I fix this error? Should I also update the chromedriver and headless? What versions should I chose?

@Darshit-dev
Copy link

Same issue I am facing while runing on aws lambda

@umihico
Copy link

umihico commented Mar 31, 2024

I hope my repository can be of some help

https://github.com/umihico/docker-selenium-lambda/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants