|
| 1 | +from seleniumwire import webdriver |
| 2 | +from selenium.webdriver.firefox.options import Options |
| 3 | +import Turquoise_Logger |
| 4 | + |
| 5 | + |
| 6 | +logg = Turquoise_Logger.Logger() |
| 7 | +log = logg.logging() |
| 8 | +initial_url = "https://www.google.com" |
| 9 | + |
| 10 | +options = Options() |
| 11 | +options.add_argument('--headless') |
| 12 | +options.set_preference('dom.webnotifications.enabled', False) |
| 13 | +options.set_preference('dom.push.enabled', False) |
| 14 | +options.set_preference('dom.webdriver.enabled', False) |
| 15 | +options.set_preference('useAutomationExtension', False) |
| 16 | +options.set_preference('privacy.trackingprotection.enabled', True) |
| 17 | +profile_path = open('profile_path', 'r').read() |
| 18 | + |
| 19 | +driver = webdriver.Firefox(firefox_profile=profile_path, options=options) |
| 20 | +driver.implicitly_wait(10) |
| 21 | + |
| 22 | +def connection_attempts(initial_url=initial_url, attempts_count=2): |
| 23 | + '''Commits attempts_count connection attempts to the given initial_url''' |
| 24 | + error = None |
| 25 | + while attempts_count: |
| 26 | + try: |
| 27 | + driver.get(initial_url) |
| 28 | + except Exception as error: |
| 29 | + log.error(f'{error}') |
| 30 | + |
| 31 | + attempts_count -= 1 |
| 32 | + |
| 33 | + if not error: |
| 34 | + attempts_num = attempts_count |
| 35 | + attempts_count = 0 |
| 36 | + log.debug(f'Realized in {attempts_num} attempts') |
| 37 | + elif attempts_count == 0: |
| 38 | + log.debug('Failed to connect') |
| 39 | + |
| 40 | + |
| 41 | +def requests_vars_get(): |
| 42 | + '''Outputs REQ (Request URL), STAT (Status Code) and CT (Content Type) within responses in requests''' |
| 43 | + for request in driver.requests: |
| 44 | + if request.response: |
| 45 | + log.error( |
| 46 | + f'REQ: {request.url}' |
| 47 | + ) |
| 48 | + |
| 49 | + log.debug( |
| 50 | + f'STAT: {request.response.status_code}' |
| 51 | + ) |
| 52 | + |
| 53 | + log.debug( |
| 54 | + 'CT:' + request.response.headers['content-type'] + '\n' |
| 55 | + ) |
| 56 | + |
| 57 | +connection_attempts() |
| 58 | +requests_vars_get() |
| 59 | + |
| 60 | +driver.quit() |
0 commit comments