Обновить auto_cookies.py

Добавление параметра прокси в настройки Chrome, добавлена переменная ENABLE_LOGIN для отключения функции логина в акаунты, добавление переменной для указания количества создаваемых профилей Chrome
This commit is contained in:
evgeniy_t 2025-02-10 01:38:08 +05:00
parent 509c823884
commit 3fee94cb1b

View File

@ -8,19 +8,24 @@ from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
# Конфигурация
BASE_COOKIES_PATH = "/root/script/cookies" # Базовый путь для сохранения cookies BASE_COOKIES_PATH = "/root/script/cookies" # Базовый путь для сохранения cookies
PRIVATE_KEY_PATH = "id_rsa" # Путь к приватному ключу для SCP PRIVATE_KEY_PATH = "id_rsa" # Путь к приватному ключу для SCP
SERVER_USER = "root" # Пользователь на удалённом сервере SERVER_USER = "root" # Пользователь на удалённом сервере
SERVER_IP = "45.140.146.245" # IP удалённого сервера SERVER_IP = "45.140.146.245" # IP удалённого сервера
REMOTE_COOKIES_PATH = "/usr/script/cookies_" # Путь на удалённом сервере REMOTE_COOKIES_PATH = "/usr/script/cookies_" # Путь на удалённом сервере
BASE_CHROME_PROFILE_PATH = "/root/.chrome-profile_" # Базовый путь к профилю Chrome BASE_CHROME_PROFILE_PATH = "/root/.chrome-profile_" # Базовый путь к профилю Chrome
# Акаунты # Включение/отключение функции логина
ACCOUNTS = [ ENABLE_LOGIN = False # Если False, скрипт просто создаст профиль и откроет YouTube
{"email": "rugikmeg@gmail.com", "password": "k88mGHVQ"},
{"email": "13ivanill2025@gmail.com", "password": "k88mGHVQ"},
# Количество создаваемых профилей
NUM_PROFILES = 5 # Сколько профилей Chrome создать
# Аккаунты
ACCOUNTS = [
{"email": "rugikmeg@gmail.com", "password": "k88mGHVQ", "proxy": "socks5://127.0.0.1:1080"},
{"email": "13ivanill2025@gmail.com", "password": "k88mGHVQ", "proxy": "socks5://127.0.0.1:1081"},
] ]
def is_profile_created(profile_index): def is_profile_created(profile_index):
@ -120,7 +125,7 @@ def transfer_cookies_via_scp(profile_index):
print(f"Общая ошибка для профиля {profile_index}: {e}") print(f"Общая ошибка для профиля {profile_index}: {e}")
return False return False
def process_profile(profile_index, email, password): def process_profile(profile_index, email, password, proxy):
"""Обработка одного профиля.""" """Обработка одного профиля."""
try: try:
# Настройки Chrome # Настройки Chrome
@ -135,9 +140,14 @@ def process_profile(profile_index, email, password):
options.add_argument(f"--user-data-dir={profile_path}") options.add_argument(f"--user-data-dir={profile_path}")
options.add_argument("--profile-directory=Default") options.add_argument("--profile-directory=Default")
# Добавляем прокси
if proxy:
options.add_argument(f"--proxy-server={proxy}")
# Запуск браузера # Запуск браузера
driver = webdriver.Chrome(options=options) driver = webdriver.Chrome(options=options)
if ENABLE_LOGIN:
# Проверка авторизации # Проверка авторизации
if is_profile_created(profile_index): if is_profile_created(profile_index):
print(f"Профиль {profile_index} уже создан. Проверяем авторизацию...") print(f"Профиль {profile_index} уже создан. Проверяем авторизацию...")
@ -162,6 +172,11 @@ def process_profile(profile_index, email, password):
print(f"Ошибка при передаче cookies для профиля {profile_index}.") print(f"Ошибка при передаче cookies для профиля {profile_index}.")
else: else:
print(f"Ошибка при извлечении cookies для профиля {profile_index}.") print(f"Ошибка при извлечении cookies для профиля {profile_index}.")
else:
# Если логин отключен, просто открываем YouTube
print(f"Логин отключен. Профиль {profile_index} создан, открываем YouTube...")
driver.get("https://www.youtube.com")
time.sleep(5) # Даем время для загрузки страницы
driver.quit() driver.quit()
return True return True
@ -171,8 +186,10 @@ def process_profile(profile_index, email, password):
if __name__ == "__main__": if __name__ == "__main__":
print("Начинаем выполнение скрипта.") print("Начинаем выполнение скрипта.")
for profile_index, account in enumerate(ACCOUNTS, start=1): for profile_index in range(1, NUM_PROFILES + 1):
# Выбираем аккаунт по кругу, если количество профилей больше, чем аккаунтов
account = ACCOUNTS[(profile_index - 1) % len(ACCOUNTS)]
print(f"Обработка профиля {profile_index}...") print(f"Обработка профиля {profile_index}...")
process_profile(profile_index, account["email"], account["password"]) process_profile(profile_index, account["email"], account["password"], account.get("proxy"))
print("Все профили обработаны.") print("Все профили обработаны.")