What I need
I have a Python Selenium script. When I run it on my local Ubuntu PC - it works fine But when I uploaded it to a server I face a problem. The server has no display I solved this problem with X Virtual Framebuffer display. What I need - is to automatically setup the display and run my script in the background
Problem
Now I run it manually the following way
I go to the terminal
Set the display with the following commands
export DISPLAY=:1
Xvfb $DISPLAY -screen $DISPLAY 1280x1024x16 &
Run the python script with command python3 products2.py
This works fine.
But I need it to run automatically in the background I created a conf file for supervisor and run the python script with supervisor.
[program:prod]
command = /root/lowescom/l-env/bin/python3.10 /root/lowescom/lowes_project/modules/products2.py
user = root
autorestart = true
redirect_stderr = true
stdout_logfile = /root/lowescom/lowes_project/logs/debug.log
But this don't work. Even if I set up the display manually - it doesn't work
Question
How can I run my python Selenium script in the background automatically. The display setup should also be automated.
Update
I have just tried to use no-sandbox. But still not working
chrome_options = uc.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = uc.Chrome(use_subprocess=True, options=chrome_options)
CodePudding user response:
if you are using chromedriver you should set the option:
chrome_options.add_argument('--no-sandbox')
for firefox you can check the pyvirtualdisplay module.