import asyncio from playwright.async_api import async_playwright import logging import time # Setup the logging logging.basicConfig(level=logging.INFO, format='%(message)s') # Log a message at the start of your script logging.info('Docker Container Started') async def run(): logging.info('Docker Container Started v2') async with async_playwright() as p: logging.info('Trying to launch Firefox...') browser = await p.firefox.launch(headless=True) logging.info('Firefox launched successfully.') page = await browser.new_page() logging.info('All fine until here') await page.goto('https://agogmail.com/', wait_until="domcontentloaded") logging.info('Entered ago-gmail') await page.wait_for_selector('.btn.btn-light.dropdown-toggle') await page.click('.btn.btn-light.dropdown-toggle') await page.wait_for_selector('a.changeMailbox[data-type="1"]') await page.click('a.changeMailbox[data-type="1"]') await asyncio.sleep(3) input_field = await page.query_selector('#active-mail') email = await input_field.get_attribute('value') logging.info("Active Mail Value: %s", email) form_page = await browser.new_page() await form_page.goto('https://altaregistrazione.net/') input_fields = await form_page.query_selector_all('input') await input_fields[0].fill(email) logging.info("Filled email: %s", email) await input_fields[1].fill(email) logging.info("Filled password") await input_fields[2].fill(email) logging.info("Filled confirm password") radio_buttons = await form_page.query_selector_all('input[type="radio"]') await radio_buttons[0].check() logging.info("Checked radio button") await form_page.wait_for_selector('.v-btn--block', state='visible') await form_page.click('.v-btn--block') logging.info("Continua Button Clicked") logging.info("Form-filled") await page.bring_to_front() await asyncio.sleep(8) await page.click('#refresh') await page.wait_for_function("document.querySelector('#message-list tr.font-bold')") all_mails = await page.query_selector_all('#message-list tr.font-bold') for email in all_mails: link = await email.query_selector('td:first-child a') sender_name = await link.inner_text() if "Altadefinizione" in sender_name: href = await link.get_attribute('href') full_url = f'https://agogmail.com/{href}' logging.info("Full URL: %s", full_url) mail_page = await browser.new_page() await mail_page.goto(full_url) await asyncio.sleep(5) verify_link = await mail_page.query_selector('.button.button-primary') verify_link_href = await verify_link.get_attribute('href') logging.info('Verification Link: %s', verify_link_href) await mail_page.goto(verify_link_href) await asyncio.sleep(5) cookies_list = await mail_page.context.cookies() for cookie in cookies_list: if cookie['name'] == 'ap_session': logging.info('ap_session cookie: %s', cookie['value']) await mail_page.close() break await browser.close() asyncio.run(run()) #while True: # try: # # your existing code here # asyncio.run(run()) #except Exception as e: # logging.error(f"An error occurred: {e}") #finally: # # sleep for 10 minutes # time.sleep(5 * 60)