0

I'm trying to run my selenium script on Ubuntu 22.04. VPS and get the error "AttributeError: 'Service' object has no attribute 'process'". However, if I run this script on my Ubuntu machine, it works fine as it should. What should I do?

Code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from bs4 import BeautifulSoup as bs4

import discord
from discord.ext import commands
   
def get_html_source(url: str):
    chrome_driver_binary = '/home/romik/Projects/hasuki_bot/chromedriver'
    options = Options()
    options.add_argument("--start-maximized") #open Browser in maximized mode
    options.add_argument("--no-sandbox") #bypass OS security model
    options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
    options.add_argument("--headless=new")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(executable_path=chrome_driver_binary, options = options)
    driver.get(url)
    try:
        with open("source-page.html", "w", encoding="utf-8") as file:
            time.sleep(10)
            file.write(driver.page_source)
    except Exception as ex:
        print(ex)
    finally:
        driver.close()
        driver.quit()

if __name__ == "__main__":
    get_html_source("https://ubuntu.com/")
syrok
  • 65
  • 4

1 Answers1

0

executable_path has been deprecated and now using you have to pass in a Service object as follows:

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

options = Options()
options.add_argument("--headless=new")
s = Service('/home/romik/Projects/hasuki_bot/chromedriver')
driver = webdriver.Chrome(service=s, options=options)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352