Обновить auto_cookies.py
Добавление параметра прокси в настройки Chrome, добавлена переменная ENABLE_LOGIN для отключения функции логина в акаунты, добавление переменной для указания количества создаваемых профилей Chrome
This commit is contained in:
parent
509c823884
commit
3fee94cb1b
@ -8,19 +8,24 @@ from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
# Конфигурация
|
||||
BASE_COOKIES_PATH = "/root/script/cookies" # Базовый путь для сохранения cookies
|
||||
PRIVATE_KEY_PATH = "id_rsa" # Путь к приватному ключу для SCP
|
||||
SERVER_USER = "root" # Пользователь на удалённом сервере
|
||||
SERVER_IP = "45.140.146.245" # IP удалённого сервера
|
||||
REMOTE_COOKIES_PATH = "/usr/script/cookies_" # Путь на удалённом сервере
|
||||
|
||||
BASE_CHROME_PROFILE_PATH = "/root/.chrome-profile_" # Базовый путь к профилю Chrome
|
||||
|
||||
# Акаунты
|
||||
ACCOUNTS = [
|
||||
{"email": "rugikmeg@gmail.com", "password": "k88mGHVQ"},
|
||||
{"email": "13ivanill2025@gmail.com", "password": "k88mGHVQ"},
|
||||
# Включение/отключение функции логина
|
||||
ENABLE_LOGIN = False # Если False, скрипт просто создаст профиль и откроет YouTube
|
||||
|
||||
# Количество создаваемых профилей
|
||||
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):
|
||||
@ -120,7 +125,7 @@ def transfer_cookies_via_scp(profile_index):
|
||||
print(f"Общая ошибка для профиля {profile_index}: {e}")
|
||||
return False
|
||||
|
||||
def process_profile(profile_index, email, password):
|
||||
def process_profile(profile_index, email, password, proxy):
|
||||
"""Обработка одного профиля."""
|
||||
try:
|
||||
# Настройки Chrome
|
||||
@ -135,33 +140,43 @@ def process_profile(profile_index, email, password):
|
||||
options.add_argument(f"--user-data-dir={profile_path}")
|
||||
options.add_argument("--profile-directory=Default")
|
||||
|
||||
# Добавляем прокси
|
||||
if proxy:
|
||||
options.add_argument(f"--proxy-server={proxy}")
|
||||
|
||||
# Запуск браузера
|
||||
driver = webdriver.Chrome(options=options)
|
||||
|
||||
# Проверка авторизации
|
||||
if is_profile_created(profile_index):
|
||||
print(f"Профиль {profile_index} уже создан. Проверяем авторизацию...")
|
||||
if not is_logged_in(driver):
|
||||
print(f"Пользователь не авторизован. Пытаемся войти...")
|
||||
if ENABLE_LOGIN:
|
||||
# Проверка авторизации
|
||||
if is_profile_created(profile_index):
|
||||
print(f"Профиль {profile_index} уже создан. Проверяем авторизацию...")
|
||||
if not is_logged_in(driver):
|
||||
print(f"Пользователь не авторизован. Пытаемся войти...")
|
||||
if not login_to_youtube(driver, email, password):
|
||||
print(f" Не удалось авторизоваться для профиля {profile_index}.")
|
||||
driver.quit()
|
||||
return False
|
||||
else:
|
||||
print(f"Профиль {profile_index} не создан. Создаем и авторизуемся...")
|
||||
if not login_to_youtube(driver, email, password):
|
||||
print(f" Не удалось авторизоваться для профиля {profile_index}.")
|
||||
driver.quit()
|
||||
return False
|
||||
else:
|
||||
print(f"Профиль {profile_index} не создан. Создаем и авторизуемся...")
|
||||
if not login_to_youtube(driver, email, password):
|
||||
print(f" Не удалось авторизоваться для профиля {profile_index}.")
|
||||
driver.quit()
|
||||
return False
|
||||
|
||||
# Извлекаем куки
|
||||
if extract_cookies(driver, profile_index):
|
||||
if transfer_cookies_via_scp(profile_index):
|
||||
print(f" Процесс завершён успешно для профиля {profile_index}.")
|
||||
# Извлекаем куки
|
||||
if extract_cookies(driver, profile_index):
|
||||
if transfer_cookies_via_scp(profile_index):
|
||||
print(f" Процесс завершён успешно для профиля {profile_index}.")
|
||||
else:
|
||||
print(f"Ошибка при передаче cookies для профиля {profile_index}.")
|
||||
else:
|
||||
print(f"Ошибка при передаче cookies для профиля {profile_index}.")
|
||||
print(f"Ошибка при извлечении cookies для профиля {profile_index}.")
|
||||
else:
|
||||
print(f"Ошибка при извлечении cookies для профиля {profile_index}.")
|
||||
# Если логин отключен, просто открываем YouTube
|
||||
print(f"Логин отключен. Профиль {profile_index} создан, открываем YouTube...")
|
||||
driver.get("https://www.youtube.com")
|
||||
time.sleep(5) # Даем время для загрузки страницы
|
||||
|
||||
driver.quit()
|
||||
return True
|
||||
@ -171,8 +186,10 @@ def process_profile(profile_index, email, password):
|
||||
|
||||
if __name__ == "__main__":
|
||||
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}...")
|
||||
process_profile(profile_index, account["email"], account["password"])
|
||||
process_profile(profile_index, account["email"], account["password"], account.get("proxy"))
|
||||
|
||||
print("Все профили обработаны.")
|
||||
Loading…
x
Reference in New Issue
Block a user