-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
78 lines (58 loc) · 3.55 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from dotenv import load_dotenv
from domconnect_selenium import xpaths
from domconnect_selenium import validate_date_time, validate_ip_port, second_captcha_routine, first_captcha_routine
from loguru import logger
load_dotenv()
email, password = os.getenv('EMAIL'), os.getenv('PASSWORD')
def main():
driver = webdriver.Chrome(service=Service(executable_path='chromedriver-win64/chromedriver.exe'))
logger.info('Открываем сайт')
driver.get('https://proxy6.net/')
logger.debug('Ждём появления кнопки открытия окна входа и кликаем её')
WebDriverWait(driver, 20).until(EC.presence_of_element_located(
(By.XPATH, xpaths.OPEN_LOGIN_MENU))).click()
logger.debug('Ждём появления области ввода для email и области ввода пароля')
email_field = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
(By.XPATH, xpaths.EMAIL_INPUT)))
password_field = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
(By.XPATH, xpaths.PASSWORD_INPUT)))
logger.debug('Вставляем наши реквизиты для входа')
email_field.send_keys(email)
password_field.send_keys(password)
logger.debug('Ищём кнопку для входа в аккаунт')
login_submit_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
(By.XPATH, xpaths.LOGIN_SUBMIT)))
logger.info('Ожидаем заполнения капчи')
if not (table_of_proxies := first_captcha_routine(driver, login_submit_button)):
logger.info('Ищем элемент после успешного входа в аккаунт (возможна вторая капча)')
table_of_proxies = second_captcha_routine(driver, login_submit_button)
result = []
logger.info('Устанавливаем максимальный размер окна')
driver.maximize_window()
logger.info('Начинаем поиск нужных данных')
for row in table_of_proxies.find_elements(By.XPATH, xpaths.PROXIES_TABLE_ELEMENT):
ip_port = row.find_element(By.XPATH, xpaths.IP_PORT).text.strip()
expiration_date = row.find_element(By.XPATH, xpaths.EXPIRATION_DATE).text.strip()
if not validate_ip_port(ip_port):
logger.warning(f'Не пройдена валидация ip_port - {ip_port}')
if not validate_date_time(expiration_date):
logger.warning(f'Не пройдена валидация expiration_date {expiration_date}, ищем в другом месте')
# hotfix
expiration_date = row.find_element(By.XPATH, xpaths.EXPIRATION_DATE_SMALL_WINDOW).text.strip()
if 'д' in expiration_date:
d_index = expiration_date.index('д')
expiration_date = expiration_date[d_index + 1:].strip()
if not validate_date_time(expiration_date):
logger.error(f'Валидация не пройдена повторно expiration_date {expiration_date}')
result.append(f"{ip_port} - {expiration_date}")
logger.success(f'Успешно собрали данные: {ip_port} - {expiration_date}')
for el in result:
print(el)
if __name__ == '__main__':
main()