im currently trying to develop a Webpage to log into some Accounts on different Websites.
For this i created a Script which starts a selenium session, gets onto the website and logs me in, all working fine.
My real problem now lies in the control of that session through a Website hosted by an apache2 Service which runs on the same server.
I use this code to run the Script, refactored from this posts answer:
<?php
$cmd = "python3 /var/scripts/LoginScript.py yes";
$output = shell_exec($cmd. ' 2>&1 > out.log');
echo $output;
?>
while /var/scripts/LoginScript.py
being the script and yes
a necessary parameter.
The following script is the first part of what the login script looks like, manually run from the commandline everything works fine but as soon as i start it through php the script only works until it tries to create the driver. (last message logged is "Maybe here?")
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
import sys
import os
import dbConn as db
import time
import pickle
print("Starting login process...")
#Get card signature from commandline arguments
card_signature = str(sys.argv[1])
#Get wp-user from provided card signature
wpUser = db.getWPUser(card_signature)
#get example-user from wp-user
user = db.getData(wpUser[0])
print("Connecting to Example, please hold on")
#Start url to connect to (in this case login page from example)
url = "https://example.page.com"
#Setting options for Firefox to run headless and in incognito mode, as well as to ignore
#certificate errors
options = webdriver.FirefoxOptions()
options.add_argument("--ignore-certificate-errors")
options.add_argument("--headless")
options.add_argument("--incognito")
print("Maybe here?")
#Create driver with the previously set options
driver = webdriver.Firefox(options=options)
print("also here?")
#Go to website
driver.get(url)
dbConn.py is a simple handler for database access to get account information (username, password)
Further explanation of the problem and what i've tried so far:
The apache service has enough rights to start the file (added www-data for test case to sudoers and modified file privileges)
As i said before, the last thing logged is the "Maybe here?" message, i already tried to raise the request timeout value to 120seconds but im not to sure if this works right as the site canceles the script after 60 to 70 seconds.
If i comment out the driver
part the code runs as smooth as butter, except not doing what i want it to as there is no real selenium session.
Originally i wanted to start the script in a screen but that didn't work out either as the screen starts but the script won't. (not really a problem for this post but may be published in another form as this is another problem - just mentioned it for informational purpose)
If i open the page with the php script and stop reloading after 20 seconds the output is already Maybe here?
but if the scripts cancels automatically after 60 to 70 seconds the output is still stuck at Maybe here?
, maybe Apache has some problems with handling selenium? That is the only idea i've got as i haven't found no reasonable way to log the errors (if there are any?)
I hope you can help me out!
Thanks (anyway).