S
S
Sergey2020-10-15 08:35:05
Google Chrome
Sergey, 2020-10-15 08:35:05

How to run selenium from chrome on vds ubuntu server?

Good day, great Linux Gurus,
I turn to you for help . On a local machine, I created an
instagram parser in a bunch of selenium chrome python beautifulsoup .

Traceback (most recent call last):
File "instagram.py", line 10, in
driver = webdriver.Chrome()
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/chrome/webdriver .py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session( capabilities, browser_profile)
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321,in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)


The parser code
from bs4 import BeautifulSoup
from selenium import webdriver
driver=webdriver.Chrome()
driver.get('https://www.instagram.com/support_point/')
html=driver.page_source
soup=BeautifulSoup(html, 'html.parser')
items=soup.find_all('div', class_="v1Nh3")
driver.quit()


Help me decide please

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-10-15
@hottabxp

On the VPS server, add the following options to the script:

options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('--no-sandbox')

Full code:
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('--no-sandbox')
driver=webdriver.Chrome(options=options)

driver.get('https://www.instagram.com/support_point/')

print(driver.title)
driver.quit()

Just tested on a clean VPS (Ubuntu 20.04):
5f87e78851898980459713.png

F
FasterTans, 2020-10-15
@FasterTans

How to properly run Selenium on a VPS?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question