Mythus commited on
Commit
1458aea
1 Parent(s): 31ceefd

Upload generator.py

Browse files
Files changed (1) hide show
  1. generator.py +111 -0
generator.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ from playwright.async_api import async_playwright
3
+
4
+ async def run():
5
+ async with async_playwright() as p:
6
+ browser = await p.firefox.launch(headless=False)
7
+ page = await browser.new_page()
8
+
9
+ await page.goto('https://agogmail.com/')
10
+ # Click the dropdown menu button first
11
+ await page.wait_for_selector('.btn.btn-light.dropdown-toggle')
12
+ await page.click('.btn.btn-light.dropdown-toggle')
13
+
14
+ # Then click the change mailbox button
15
+ await page.wait_for_selector('a.changeMailbox[data-type="1"]')
16
+ await page.click('a.changeMailbox[data-type="1"]')
17
+ await asyncio.sleep(3)
18
+ # Get active-mail value and print
19
+ input_field = await page.query_selector('#active-mail')
20
+ email = await input_field.get_attribute('value')
21
+ print("Active Mail Value: ", email)
22
+
23
+ # Go to the form page
24
+ form_page = await browser.new_page()
25
+ await form_page.goto('https://altaregistrazione.net/')
26
+
27
+ # Get all input fields
28
+ input_fields = await form_page.query_selector_all('input')
29
+
30
+ # Filling in the fields
31
+ await input_fields[0].fill(email) # Assuming first field is the email field
32
+ print("Filled email: ", email)
33
+
34
+ await input_fields[1].fill(email) # Assuming second field is the password field
35
+ print("Filled password")
36
+
37
+ await input_fields[2].fill(email) # Assuming third field is the confirm password field
38
+ print("Filled confirm password")
39
+
40
+ # Check the radio button
41
+ radio_buttons = await form_page.query_selector_all('input[type="radio"]')
42
+ await radio_buttons[0].check() # Assuming it's the first radio button you want to check
43
+ print("Checked radio button")
44
+
45
+ # Before clicking the button, make sure the page loads the dynamic content.
46
+ # we are waiting for the button to be visible.
47
+ await form_page.wait_for_selector('.v-btn--block', state='visible')
48
+
49
+ # Click the "Continua" button.
50
+ await form_page.click('.v-btn--block')
51
+ print("Continua Button Clicked")
52
+
53
+ # print a message once complete.
54
+ print("Form-filled\n")
55
+
56
+ await page.bring_to_front()
57
+ await asyncio.sleep(8)
58
+ await page.click('#refresh') # click the refresh button
59
+
60
+ # wait for an email with class 'font-bold' to appear
61
+ await page.wait_for_function("document.querySelector('#message-list tr.font-bold')")
62
+
63
+ # Get active-mail value and print
64
+ mail_field = await page.query_selector('#active-mail')
65
+ mail = await mail_field.get_attribute('value')
66
+ print("Active Mail Value: ", mail)
67
+
68
+ # Get all unread mails with class 'font-bold'
69
+ all_mails = await page.query_selector_all('#message-list tr.font-bold')
70
+
71
+ for email in all_mails:
72
+ link = await email.query_selector('td:first-child a')
73
+ sender_name = await link.inner_text()
74
+
75
+ if "Altadefinizione" in sender_name:
76
+ href = await link.get_attribute('href')
77
+ full_url = f'https://agogmail.com/{href}'
78
+ print("Full URL: ", full_url)
79
+
80
+ # Open new page and go to the full URL
81
+ mail_page = await browser.new_page()
82
+ await mail_page.goto(full_url)
83
+
84
+ # Wait for the page to load
85
+ await asyncio.sleep(5)
86
+
87
+ # Get the verification link
88
+ verify_link = await mail_page.query_selector('.button.button-primary')
89
+ verify_link_href = await verify_link.get_attribute('href')
90
+
91
+ print('Verification Link: ', verify_link_href)
92
+
93
+ # Open the verification link
94
+ await mail_page.goto(verify_link_href)
95
+
96
+ # Wait for the page to load
97
+ await asyncio.sleep(5)
98
+
99
+ # Get cookies
100
+ cookies_list = await mail_page.context.cookies()
101
+ for cookie in cookies_list:
102
+ if cookie['name'] == 'ap_session':
103
+ print('ap_session cookie: ', cookie['value'])
104
+
105
+ await mail_page.close()
106
+
107
+ break # Stop the loop once a valid email from 'Altadefinizione' is found
108
+
109
+ await browser.close()
110
+
111
+ asyncio.run(run())