Я управляю около 150 учетными записями электронной почты своей компании и написал сценарий Python для Selenium WebDriver, который автоматизирует действия (удаление спама, очистка корзины, ...) одна учетная запись за другой, несколько раз в день, и этослишком медленный и постоянно падает. Я читал, что Selenium Grid с Docker в Amazon AWS может справиться с этой задачей, и кажется, что «параллельный» вариант для Selenium WebDriver тоже может.
Что мне нужно сделать одновременно:
1) Вход в систему (все учетные записи)
2) Выполнение действий (удаление спама, очистка корзины, ...)
3) Закрытие экземпляров Chrome
В настоящее время я должен использовать цикл for для создания в 150 раз одних и тех же инструкций, которые я храню в списках, и это совсем не оптимизировано, это приводит к сбою моего компьютера ... В двух словах,Я знаю, что это не тот путь, и я с нетерпением жду возможности одновременной параллельной работы.
Вот сокращенная версия кода, который я использую:
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
Послепросмотр интернета в течение нескольких дней безрезультатно, любая помощь приветствуется. Большое спасибо!