Я пытаюсь очистить веб-сайт, используя Selenium, драйвер gecko и firefox. Если я выполняю скрипт как root или как обычный пользователь, он работает нормально. Но когда я запускаю его как apache (то есть, как он будет работать в производственном процессе), он терпит неудачу. Версии -
Mozilla Firefox 72.0
geckodriver 0.26.0
Я установил уровень журнала для трассировки. Записи, появляющиеся в геккологе
1579004036460 mozrunner::runner INFO Running command: "/bin/firefox" "-marionette" "--disable-extensions" "--disable-infobars" "--disable-images" "--headless" "--disable-gpu" "--no-sandbox" "--disable-setuid-sandbox" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileKkQRyT"
1579004036461 geckodriver::marionette DEBUG Waiting 60s to connect to browser on 127.0.0.1:37317
*** You are running in headless mode.
(firefox:21013): dconf-CRITICAL **: 12:14:56.520: unable to create directory '/usr/share/httpd/.cache/dconf': Permission denied. dconf will not work properly.
(firefox:21013): dconf-CRITICAL **: 12:14:56.521: unable to create directory '/usr/share/httpd/.cache/dconf': Permission denied. dconf will not work properly.
(firefox:21013): dconf-CRITICAL **: 12:14:56.521: unable to create directory '/usr/share/httpd/.cache/dconf': Permission denied. dconf will not work properly.
(firefox:21013): dconf-CRITICAL **: 12:14:56.521: unable to create directory '/usr/share/httpd/.cache/dconf': Permission denied. dconf will not work properly.
(firefox:21013): dconf-CRITICAL **: 12:14:56.524: unable to create directory '/usr/share/httpd/.cache/dconf': Permission denied. dconf will not work properly.
1579004096533 mozrunner::runner DEBUG Killing process 21013
1579004096537 webdriver::server DEBUG <- 500 Internal Server Error {"value":{"error":"timeout","message":"connection refused","stacktrace":""}}
В сеансе, где я выполняю сценарий, это вывод
Traceback (most recent call last):
File "/var/www/html/***.py", line 36, in <module>
scrap_price()
File "/var/www/html/***.py", line 26, in scrap_price
driver = webdriver.Firefox(firefox_binary=binary, executable_path=gecko, options=options,firefox_profile=firefoxProfile, service_log_path='/tmp/geckodriver.log')
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: connection refused
Соответствующие разделы кода
options = Options()
options.add_argument('--disable-extensions')
options.add_argument('--disable-infobars')
options.add_argument('--disable-images')
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-setuid-sandbox')
options.log.level = 'trace'
gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
binary = FirefoxBinary('/bin/firefox')
firefoxProfile = webdriver.FirefoxProfile()
firefoxProfile.set_preference('permissions.default.stylesheet', 2)
firefoxProfile.set_preference('permissions.default.image', 2)
firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so','false')
driver = webdriver.Firefox(firefox_binary=binary, executable_path=gecko, options=options,firefox_profile=firefoxPro
file, service_log_path='/tmp/geckodriver.log')
driver.get(urlpage)
ОС CentOS Linux, версия 7.6, с поддержкой SE Linux. Но sealert не показывает никаких ошибок, связанных с этим.