Как запустить selenium с chrome на vds ubuntu server?

Доброго времени суток о великие Linux-Гуру
Обращаюсь к Вам за помощью
На локальной машине сваял парсер инстаграма в связке selenium chrome python beautifulsoup
Но мне необходима работа vds c ubuntu server а там ну не в какую (((

Вот такой беспредел пишет:
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.)


Сам код парсера
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()


Помогите решить прошу
  • Вопрос задан
  • 3624 просмотра
Пригласить эксперта
Ответы на вопрос 2
hottabxp
@hottabxp
Сначала мы жили бедно, а потом нас обокрали..
На VPS сервере в скрипт нужно добавить следующие опции:
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('--no-sandbox')

Полный код:
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()

Только что проверил на чистой VPS(Ubuntu 20.04):
5f87e78851898980459713.png
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы