Question

could i use selenium build-in function on digitalocean

I created selenium and I want to deploy my script on the function I want to know if I could run selenium in the function if yes please let me know how I can do it. please feel; free to share with me another way I can deploy the Selenium code thanks


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
August 20, 2023

Hi there,

I believe that running Selenium in serverless environments can be a complex task due to the need for a browser or browser-like environment.

I think that using a Droplet might be a more suitable solution for this use-case as you will have full access to the server and you will be able to install and configure the server to exactly meet your requirements.

Here is a quick tutorial on how to do that:

1. Set Up a New Droplet

If you haven’t already, create a new Ubuntu Droplet on DigitalOcean:

https://docs.digitalocean.com/products/droplets/how-to/create/

2. Connect to the Droplet

SSH into your Droplet using the command:

ssh username@your-droplet-ip

https://docs.digitalocean.com/products/droplets/how-to/connect-with-ssh/

3. Install Google Chrome (or Another Web Browser)

You’ll need a web browser to run Selenium. Here’s how you can install Google Chrome:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt-get -f install -y

4. Install ChromeDriver

You’ll also need ChromeDriver, which allows Selenium to interface with the Chrome browser:

wget https://chromedriver.storage.googleapis.com/114.0.5735.90/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

Make sure to download a version of ChromeDriver that is compatible with the installed version of Google Chrome.

5. Install Python (or Another Language) and Selenium

Install Python, pip, and Selenium:

sudo apt-get update
sudo apt-get install python3 python3-pip
pip3 install selenium

6. Write Your Selenium Script

You can now write your Selenium script using the headless option:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless")

driver = webdriver.Chrome(options=options)
driver.get("https://www.example.com")

7. Run Your Script

You can now run your Selenium script with the following:

python3 your-script.py

For more information, I could also suggest these tutorials here as well:

https://www.digitalocean.com/community/tutorials?q=[selenium]&hits_per_page=12

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel