I manage around 150 email accounts of my company, and I wrote a Python script for Selenium WebDriver that automates actions (deleting spams, emptying the trash,...) one account after the other, several times a day, and it is way too slow, and crashes all the time. I read that Selenium Grid with Docker on Amazon AWS could do the job, and it seems that the "parallel" option for Selenium WebDriver could too.
What I need to do simultaneously :
1) Login (all the accounts)
2) Perform actions (delete spams, empty the trash,...)
3) Close the Chrome instances
I currently have to use a for loop to create 150 times the same instructions that I store in lists, and this is not optimized at all, it makes my computer crash... In a nutshell, I know it's not the way to go and I'm looking forward to have this running simultaneously in parallel.
Here is a shortened version of the code I am using:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
## GET THE USERS' EMAILS
emails = []
pwds = []
with open("users.txt", "r") as users_file: # Open the text file containing emails and pwds
for line in users_file:
email_and_pwd = line.split() # Extract the line of the .txt file as a list
emails.append(email_and_pwd[0]) # Add the email in the emails list
pwds.append(email_and_pwd[1]) # Add the pwd in the pwds list
nbr_users = len(emails) # number of users
## CREATE LISTS OF INSTRUCTIONS THAT WILL BE EXECUTED LATER AS CODE
create_new_driver = []
go_to_email_box = []
fill_username_box = []
fill_password_box = []
# Here I have the same type of lines to create lists that will contain the instructions to click on the Login button, then delete spams, then empty the trash, etc...
## FILL THE LISTS WITH INSTRUCTIONS AS STRINGS
for i in range(nbr_users):
create_new_driver_element = 'driver' + str(i) + ' = webdriver.Chrome(options = chrome_options)'
create_new_driver.append(create_new_driver_element)
# Here I have the same type of lines to create the rest of the instructions to fill the lists
## EXECUTE THE INSTRUCTIONS SAVED IN THE LISTS
for user in range(nbr_users):
exec(create_new_driver[user])
# Here I have the same type of lines to execute the code contained in the previously created lists
After browsing the internet for days to no results, any kind of help is appreciated. Thank you very much !