forked from thewhiteh4t/nexfil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
headless.py
46 lines (44 loc) · 1.8 KB
/
headless.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
from printer import clout
from write_log import log_writer
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException, NoSuchElementException
async def test_driver(driver, url, data, timeout):
if 'Just a moment' in driver.title:
try:
match = WebDriverWait(driver, timeout).until(
EC.any_of(
EC.presence_of_element_located((By.XPATH, data['found'])),
EC.presence_of_element_located((By.XPATH, data['not_found']))
)
)
for case in data:
try:
match.find_element(By.XPATH, data[case])
if case == 'found':
await clout(url)
except NoSuchElementException:
pass
except TimeoutException:
if 'Ray ID' in driver.page_source:
log_writer(f'headless.py, Cloudflare bypass failed, {url}')
else:
log_writer(f'headless.py, Timed out, {url}')
else:
try:
match = WebDriverWait(driver, timeout).until(
EC.any_of(
EC.presence_of_element_located((By.XPATH, data['found'])),
EC.presence_of_element_located((By.XPATH, data['not_found']))
)
)
for case in data:
try:
match.find_element(By.XPATH, data[case])
if case == 'found':
await clout(url)
except NoSuchElementException:
pass
except TimeoutException:
log_writer(f'headless.py, Timed out, {url}')