Python Forum

Full Version: Script running on a server
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm new to Python and I created a script running on Chrome webdriver.
How can I create the same script that I can keep it running on a cloud server 24/7?

It's a simple bot, just login in to a website, and click on a submit button.


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.webdriver.common.by import By

driver = webdriver.Chrome('C:/chromedriver.exe')

def timekiller():
user = 'user'
psw = 'pass'
driver.get('http://www.mypage.com')
sleep(5)
driver.find_element_by_id('slogin').click()
sleep(5)
userid = driver.find_element_by_name('username').send_keys(user)
psw = driver.find_element_by_name('password').send_keys(psw)
sleep(5)
driver.find_element_by_class_name("form-group").submit()
sleep(5)
driver.get('http://xxx.com/like?type=photo')
sleep(10)
driver.find_element_by_id('get_likes_button').click()
sleep(45)
driver.get('http://www.mypage.com/logout')

while True:
try:
timekiller()
except Exception:
driver.get('http://www.mypage.com/logout')
You can add a cron job to run the script every whatever time you want.
https://www.htlinux.com/how-to-cron-jobs-in-linux/

The alternate solution is to put it in a loop and repeat and let it run indefinitely using tmux to split out of the terminal and leave while its running.
https://hackernoon.com/a-gentle-introduc...784c404340
Also, in the future, please use code tags! I went to do it for you but the indentation still looked broken, you need to make sure that the indentation is correct in your posts.