In this lesson, we will create a Mega.nz account creator using Selenium and the Request package. We will go more in depth with the Request package in later lessons. The first lesson is designed to give you some understanding of how automation works and functions.
- We will begin by using a template that I use when i have a Selenium project.
import random
import names
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC, expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException
from selenium.webdriver.chrome.service import Service
To run this project successfully, you need to install these packages.
- Go to start>Search>Type CMD>Open As Admin> copy paste the following separately
pip install Selenium
pip install names
pip install base64
pip install requests
def random_email():
loademail = ''.join(
random.choice("1234567890") for x in range(8)) #range(8)) sets the length to 8 random characters
return loademail
def random_pass():
loadpassword = ''.join(
random.choice("1234567890") for x in range(8)) #range(8)) sets the length to 8 random characters
return loadpassword
this part of the code will open chromedriver to Mega.nz, make sure Chromedriver is placed in the same path
Headless = False
def main():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("--log-level=3")
os.environ['WDM_LOG_LEVEL'] = '0'
chrome_options.add_argument(
'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36')
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
chrome_options.add_argument("window-size=500,500") #sets the chrome window size
if Headless == True:
chrome_options.add_argument('headless')
else:
pass
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://mega.nz/register")
All the code above is a template I use to start a project. I usually copy and paste it to save time.
- After this is done, we can begin automating the creation of Mega.nz accounts.
In the next step, we will use the NAMES package to complete our random email and password functions.
- The following code should be placed in the main function above:
first_name = names.get_first_name(gender='male') #Random first name, example john
last_name = names.get_last_name() #Random last name, example doe
email = first_name + last_name + random_email() + "@xitroo.com" #combines first and last names together plus adds email domain @xitroo.com, [email protected]
password = first_name + last_name + random_pass() #combines first and last names together plus adds random numbers to generate password
Headless = False
def main():
first_name = names.get_first_name(gender='male') #Random first name, example john
last_name = names.get_last_name() #Random last name, example doe
email = first_name + last_name + random_email() + "@xitroo.com" #combines first and last names together plus adds email domain @xitroo.com, [email protected]
password = first_name + last_name + random_pass() #combines first and last names together plus adds random numbers to generate password
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("--log-level=3")
os.environ['WDM_LOG_LEVEL'] = '0'
chrome_options.add_argument(
'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36')
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
chrome_options.add_argument("window-size=500,500") #sets the chrome window size
if Headless == True:
chrome_options.add_argument('headless')
else:
pass
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://mega.nz/register")
Since Mega.nz requires you to email verify your email address, we will use a temporary email service called Xitroo.
- This email service does not have an API, so I created my own using the Request package I have used it on many websites. It allows you to verify the email address and it helps a lot, as they have multiple sub domains so if one of them is blocked you can use the others. Examples are xitroo.com, xitroo.org, xitroo.me, xitroo.fr etc...
- It is not a complicated piece of code, but it does look confusing. You only need to copy and paste the following function:
def FetchEmail(xitroo_email=None, subject=None, timeout=30):
cwd = os.getcwd()
if xitroo_email == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(xitroo_email=?)
TypeError: get_email(xitroo_email=?), Missing positional argument, xitroo_email= should have the value of the generated email. """)
input()
else:
pass
if subject == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(subject=?)
TypeError: get_email(subject=?), Missing positional argument, subject= should have the value of the email subject received. """)
input()
else:
pass
xitroo_session = requests.session()
counter = 0
while True:
counter += 1
now = datetime.datetime.now()
b = now + datetime.timedelta(0, 600)
timestamp = datetime.datetime.timestamp(b)
xitroo_response = xitroo_session.get(
"https://api.xitroo.com/v1/mails?locale=en&mailAddress=" + xitroo_email + "&mailsPerPage=25&minTimestamp=0&maxTimestamp=" + str(
timestamp))
if str(subject) in xitroo_response.text:
break
time.sleep(1)
if counter == timeout:
return print(Fore.RED + "Email timeout limit has reached")
else:
pass
email_id = re.findall('_id":"(.*?)"', xitroo_response.text)[0]
data = {
'id': email_id
}
email_body = xitroo_session.get("https://api.xitroo.com/v1/mail?locale=en&id={}".format(email_id), data=data)
bodytext = re.findall('"bodyText":"(.*?)"', email_body.text)[0]
code = base64.b64decode(bodytext)
conv_email_base64 = base64.b64encode(code)
body = base64.b64decode(conv_email_base64).decode()
return body
- All it takes is one line
# xitroo_email=email, Means the email you used to sign up to MEGA you feed it to the value of xitroo_email= which we generated the email up top and named it EMAIL
# subject=MEGA, Each email has a subject all you need to do is manually go check the email thet Mega.nz sent and grab part of the subject.
# Here are some examples, Please verfiy your email MEGA, thats the subject of the email so we only need to grab a part of it which idealy would be MEGA and feed it to # # the value of subject=
email_content = FetchEmail(xitroo_email=email, subject="MEGA")
If you are interested in this API, I have made it into a Python library you can install it by following these steps:
- Go to start>Search>Type CMD>Open As Admin> copy paste the following.
pip install xitroo-api
- Documentacion can be found Here
def FetchEmail(xitroo_email=None, subject=None, timeout=30):
cwd = os.getcwd()
if xitroo_email == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(xitroo_email=?)
TypeError: get_email(xitroo_email=?), Missing positional argument, xitroo_email= should have the value of the generated email. """)
input()
else:
pass
if subject == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(subject=?)
TypeError: get_email(subject=?), Missing positional argument, subject= should have the value of the email subject received. """)
input()
else:
pass
xitroo_session = requests.session()
counter = 0
while True:
counter += 1
now = datetime.datetime.now()
b = now + datetime.timedelta(0, 600)
timestamp = datetime.datetime.timestamp(b)
xitroo_response = xitroo_session.get(
"https://api.xitroo.com/v1/mails?locale=en&mailAddress=" + xitroo_email + "&mailsPerPage=25&minTimestamp=0&maxTimestamp=" + str(
timestamp))
if str(subject) in xitroo_response.text:
break
time.sleep(1)
if counter == timeout:
return print(Fore.RED + "Email timeout limit has reached")
else:
pass
email_id = re.findall('_id":"(.*?)"', xitroo_response.text)[0]
data = {
'id': email_id
}
email_body = xitroo_session.get("https://api.xitroo.com/v1/mail?locale=en&id={}".format(email_id), data=data)
bodytext = re.findall('"bodyText":"(.*?)"', email_body.text)[0]
code = base64.b64decode(bodytext)
conv_email_base64 = base64.b64encode(code)
body = base64.b64decode(conv_email_base64).decode()
return body
import random
import names
import selenium
import os
import base64
from termcolor import colored
import colorama
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC, expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException
from selenium.webdriver.chrome.service import Service
def random_email():
loademail = ''.join(
random.choice("1234567890") for x in range(8)) #range(8)) sets the length to 8 random characters
return loademail
def random_pass():
loadpassword = ''.join(
random.choice("1234567890") for x in range(8)) #range(8)) sets the length to 8 random characters
return loadpassword
def FetchEmail(xitroo_email=None, subject=None, timeout=30):
cwd = os.getcwd()
if xitroo_email == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(xitroo_email=?)
TypeError: get_email(xitroo_email=?), Missing positional argument, xitroo_email= should have the value of the generated email. """)
input()
else:
pass
if subject == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(subject=?)
TypeError: get_email(subject=?), Missing positional argument, subject= should have the value of the email subject received. """)
input()
else:
pass
xitroo_session = requests.session()
counter = 0
while True:
counter += 1
now = datetime.datetime.now()
b = now + datetime.timedelta(0, 600)
timestamp = datetime.datetime.timestamp(b)
xitroo_response = xitroo_session.get(
"https://api.xitroo.com/v1/mails?locale=en&mailAddress=" + xitroo_email + "&mailsPerPage=25&minTimestamp=0&maxTimestamp=" + str(
timestamp))
if str(subject) in xitroo_response.text:
break
time.sleep(1)
if counter == timeout:
return print(Fore.RED + "Email timeout limit has reached")
else:
pass
email_id = re.findall('_id":"(.*?)"', xitroo_response.text)[0]
data = {
'id': email_id
}
email_body = xitroo_session.get("https://api.xitroo.com/v1/mail?locale=en&id={}".format(email_id), data=data)
bodytext = re.findall('"bodyText":"(.*?)"', email_body.text)[0]
code = base64.b64decode(bodytext)
conv_email_base64 = base64.b64encode(code)
body = base64.b64decode(conv_email_base64).decode()
return body
def main():
first_name = names.get_first_name(gender='male') #Random first name, example john
last_name = names.get_last_name() #Random last name, example doe
email = first_name + last_name + random_email() + "@xitroo.com" #combines first and last names together plus adds email domain @xitroo.com, [email protected]
password = first_name + last_name + random_pass() #combines first and last names together plus adds random numbers to generate password
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("--log-level=3")
os.environ['WDM_LOG_LEVEL'] = '0'
chrome_options.add_argument(
'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36')
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
chrome_options.add_argument("window-size=500,500") #sets the chrome window size
if Headless == True:
chrome_options.add_argument('headless')
else:
pass
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://mega.nz/register")
The next section will be grabbing the Xpath of elements in Chrome and clicking or sending text to them.
- I will skip this step and paste the code, since you may already know how to do this step. If not, I suggest you watch this YT playlist. Learn The Basics Of Selenium Here
while __name__ == '__main__': #checks if the button is clickable on chrome tab
try:
r = driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[2]/input").is_displayed()
if r == True:
break
else:
pass
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[2]/input").send_keys(first_name) #sends first name in text box in chrome
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[3]/input").send_keys(last_name) #sends last name in text box in chrome
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[5]/input").send_keys(email) #sends email in text box in chrome
driver.find_element(By.ID, "register-password-registerpage2").click() #clicks on the password box 1
driver.find_element(By.ID, "register-password-registerpage2").send_keys(password) #sends password in text box in chrome
driver.find_element(By.ID, "register-password-registerpage3").click() #clicks on the password box 2
driver.find_element(By.ID, "register-password-registerpage3").send_keys(password) #sends password-2 in text box in chrome
driver.find_element(By.XPATH,"/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[8]/div[1]/input").click() #element clicks
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[9]/div[1]/input").click() #element clicks
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/button").click() #element clicks
import random
import names
import selenium
import os
import base64
from termcolor import colored
import colorama
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC, expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException
from selenium.webdriver.chrome.service import Service
def random_email():
loademail = ''.join(
random.choice("1234567890") for x in range(8)) #range(8)) sets the length to 8 random characters
return loademail
def random_pass():
loadpassword = ''.join(
random.choice("1234567890") for x in range(8)) #range(8)) sets the length to 8 random characters
return loadpassword
def FetchEmail(xitroo_email=None, subject=None, timeout=30):
cwd = os.getcwd()
if xitroo_email == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(xitroo_email=?)
TypeError: get_email(xitroo_email=?), Missing positional argument, xitroo_email= should have the value of the generated email. """)
input()
else:
pass
if subject == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(subject=?)
TypeError: get_email(subject=?), Missing positional argument, subject= should have the value of the email subject received. """)
input()
else:
pass
xitroo_session = requests.session()
counter = 0
while True:
counter += 1
now = datetime.datetime.now()
b = now + datetime.timedelta(0, 600)
timestamp = datetime.datetime.timestamp(b)
xitroo_response = xitroo_session.get(
"https://api.xitroo.com/v1/mails?locale=en&mailAddress=" + xitroo_email + "&mailsPerPage=25&minTimestamp=0&maxTimestamp=" + str(
timestamp))
if str(subject) in xitroo_response.text:
break
time.sleep(1)
if counter == timeout:
return print(Fore.RED + "Email timeout limit has reached")
else:
pass
email_id = re.findall('_id":"(.*?)"', xitroo_response.text)[0]
data = {
'id': email_id
}
email_body = xitroo_session.get("https://api.xitroo.com/v1/mail?locale=en&id={}".format(email_id), data=data)
bodytext = re.findall('"bodyText":"(.*?)"', email_body.text)[0]
code = base64.b64decode(bodytext)
conv_email_base64 = base64.b64encode(code)
body = base64.b64decode(conv_email_base64).decode()
return body
def main():
first_name = names.get_first_name(gender='male') #Random first name, example john
last_name = names.get_last_name() #Random last name, example doe
email = first_name + last_name + random_email() + "@xitroo.com" #combines first and last names together plus adds email domain @xitroo.com, [email protected]
password = first_name + last_name + random_pass() #combines first and last names together plus adds random numbers to generate password
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("--log-level=3")
os.environ['WDM_LOG_LEVEL'] = '0'
chrome_options.add_argument(
'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36')
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
chrome_options.add_argument("window-size=500,500") #sets the chrome window size
if Headless == True:
chrome_options.add_argument('headless')
else:
pass
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://mega.nz/register")
while __name__ == '__main__': #checks if the button is clickable on chrome tab
try:
r = driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[2]/input").is_displayed()
if r == True:
break
else:
pass
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[2]/input").send_keys(first_name) #sends first name in text box in chrome
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[3]/input").send_keys(last_name) #sends last name in text box in chrome
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[5]/input").send_keys(email) #sends email in text box in chrome
driver.find_element(By.ID, "register-password-registerpage2").click() #clicks on the password box 1
driver.find_element(By.ID, "register-password-registerpage2").send_keys(password) #sends password in text box in chrome
driver.find_element(By.ID, "register-password-registerpage3").click() #clicks on the password box 2
driver.find_element(By.ID, "register-password-registerpage3").send_keys(password) #sends password-2 in text box in chrome
driver.find_element(By.XPATH,"/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[8]/div[1]/input").click() #element clicks
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[9]/div[1]/input").click() #element clicks
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/button").click() #element clicks
mega.mp4
For the purpose of this lesson i tweaked some stuff, in my original source i had the email verification fully request based. The changes i made are miner but i wanted to make this lesson toward Selenium fully we are still gonna use the XITROO API i made to grab the Verification link but we will verfiy it using webdriver rather than request just to simplify things.
- We will be using this follwing code to get the verification link from the email.
1 - The Random Email We Created With a Xitroo.com Domain
email = first_name + last_name + random_email() + "@xitroo.com"
2 - The Xitroo API function
def FetchEmail(xitroo_email=None, subject=None, timeout=30):
- We will call the function as the code shows below
- The xitroo_email= will take the value email
- The subject= will take part of the email subject you recived, example below
email_content = FetchEmail(xitroo_email=email, subject="MEGA")
import random
import names
import selenium
import os
import base64
from termcolor import colored
import colorama
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC, expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException
from selenium.webdriver.chrome.service import Service
def random_email():
loademail = ''.join(
random.choice("1234567890") for x in range(8)) #range(8)) sets the length to 8 random characters
return loademail
def random_pass():
loadpassword = ''.join(
random.choice("1234567890") for x in range(8)) #range(8)) sets the length to 8 random characters
return loadpassword
def FetchEmail(xitroo_email=None, subject=None, timeout=30):
cwd = os.getcwd()
if xitroo_email == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(xitroo_email=?)
TypeError: get_email(xitroo_email=?), Missing positional argument, xitroo_email= should have the value of the generated email. """)
input()
else:
pass
if subject == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(subject=?)
TypeError: get_email(subject=?), Missing positional argument, subject= should have the value of the email subject received. """)
input()
else:
pass
xitroo_session = requests.session()
counter = 0
while True:
counter += 1
now = datetime.datetime.now()
b = now + datetime.timedelta(0, 600)
timestamp = datetime.datetime.timestamp(b)
xitroo_response = xitroo_session.get(
"https://api.xitroo.com/v1/mails?locale=en&mailAddress=" + xitroo_email + "&mailsPerPage=25&minTimestamp=0&maxTimestamp=" + str(
timestamp))
if str(subject) in xitroo_response.text:
break
time.sleep(1)
if counter == timeout:
return print(Fore.RED + "Email timeout limit has reached")
else:
pass
email_id = re.findall('_id":"(.*?)"', xitroo_response.text)[0]
data = {
'id': email_id
}
email_body = xitroo_session.get("https://api.xitroo.com/v1/mail?locale=en&id={}".format(email_id), data=data)
bodytext = re.findall('"bodyText":"(.*?)"', email_body.text)[0]
code = base64.b64decode(bodytext)
conv_email_base64 = base64.b64encode(code)
body = base64.b64decode(conv_email_base64).decode()
return body
def main():
first_name = names.get_first_name(gender='male') #Random first name, example john
last_name = names.get_last_name() #Random last name, example doe
email = first_name + last_name + random_email() + "@xitroo.com" #combines first and last names together plus adds email domain @xitroo.com, [email protected]
password = first_name + last_name + random_pass() #combines first and last names together plus adds random numbers to generate password
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("--log-level=3")
os.environ['WDM_LOG_LEVEL'] = '0'
chrome_options.add_argument(
'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36')
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
chrome_options.add_argument("window-size=500,500") #sets the chrome window size
if Headless == True:
chrome_options.add_argument('headless')
else:
pass
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://mega.nz/register")
while __name__ == '__main__': #checks if the button is clickable on chrome tab
try:
r = driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[2]/input").is_displayed()
if r == True:
break
else:
pass
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[2]/input").send_keys(first_name) #sends first name in text box in chrome
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[3]/input").send_keys(last_name) #sends last name in text box in chrome
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[5]/input").send_keys(email) #sends email in text box in chrome
driver.find_element(By.ID, "register-password-registerpage2").click() #clicks on the password box 1
driver.find_element(By.ID, "register-password-registerpage2").send_keys(password) #sends password in text box in chrome
driver.find_element(By.ID, "register-password-registerpage3").click() #clicks on the password box 2
driver.find_element(By.ID, "register-password-registerpage3").send_keys(password) #sends password-2 in text box in chrome
driver.find_element(By.XPATH,"/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[8]/div[1]/input").click() #element clicks
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[9]/div[1]/input").click() #element clicks
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/button").click() #element clicks
email_content = FetchEmail(xitroo_email=email, subject="MEGA")
it sends requests to the Xitroo.com servers and checks if the random email we created recived any emails, and if it has then it checks each email for a subject containing MEGA as we told the function to look for MEGA.
It sends another request to grab the message body of that email , where we can then see the content of the email and get the verification link.
will when the function finds the email and sends the 2end request to grab the content it has to decode it from HEX to UFT-8 so we can read it, here is an example of how it looks decoded
[email protected]
You have one more step remaining to activate your MEGA account.
Click on the link below to verify your email address:
https://mega.nz/#confirmQ29uZmlybUNvZGVWMt4Sgs26BgAGUOn6yHsHwUxhd3JlbmNlS2luZ18wMjM0QHhpdHJvby5jb20JTGF3cmVuY2UgS2luZ1lq3S3CeDT3
Best regards,
β Team MEGA
- we have to use a package called re which is a short name for regex here is how we do that.
Make sure to (import) re at the very top of the code
url = re.findall('https://(.*?)\n', email_content)[0] #grabs url from email to seperate it
confirmation_url = "https://" + url #adds https:// to url to auth
email_content = FetchEmail(xitroo_email=email, subject="MEGA") # function gets auth url from email
url = re.findall('https://(.*?)\n', email_content)[0] #grabs url from email to seperate it
confirmation_url = "https://" + url #adds https:// to url to auth
driver.get(confirmation_url) #opens the auth link
- We have to chosse a plan since MEGA is a cloud storage service, here how to do that.
while __name__ == '__main__': #checks if button is clickable
try:
r = driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[3]/input").is_displayed()
if r == True:
break
else:
pass
except:
pass
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[3]/input").send_keys(password)
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/button").click()
time.sleep(3)
try:
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div/div[2]/div[5]/div/div[2]/div[2]/div").click()
except:
try:
time.sleep(2)
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div/div[2]/div[5]/div/div[2]/div[2]").click()
except:
pass
import random
import names
import selenium
import os
import base64
from termcolor import colored
import colorama
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC, expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException
from selenium.webdriver.chrome.service import Service
def random_email():
loademail = ''.join(
random.choice("1234567890") for x in range(8)) #range(8)) sets the length to 8 random characters
return loademail
def random_pass():
loadpassword = ''.join(
random.choice("1234567890") for x in range(8)) #range(8)) sets the length to 8 random characters
return loadpassword
def FetchEmail(xitroo_email=None, subject=None, timeout=30):
cwd = os.getcwd()
if xitroo_email == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(xitroo_email=?)
TypeError: get_email(xitroo_email=?), Missing positional argument, xitroo_email= should have the value of the generated email. """)
input()
else:
pass
if subject == None:
print(f"""
{Fore.RED}
Traceback (an error has occurred):
File "{cwd}"
Error = get_email(subject=?)
TypeError: get_email(subject=?), Missing positional argument, subject= should have the value of the email subject received. """)
input()
else:
pass
xitroo_session = requests.session()
counter = 0
while True:
counter += 1
now = datetime.datetime.now()
b = now + datetime.timedelta(0, 600)
timestamp = datetime.datetime.timestamp(b)
xitroo_response = xitroo_session.get(
"https://api.xitroo.com/v1/mails?locale=en&mailAddress=" + xitroo_email + "&mailsPerPage=25&minTimestamp=0&maxTimestamp=" + str(
timestamp))
if str(subject) in xitroo_response.text:
break
time.sleep(1)
if counter == timeout:
return print(Fore.RED + "Email timeout limit has reached")
else:
pass
email_id = re.findall('_id":"(.*?)"', xitroo_response.text)[0]
data = {
'id': email_id
}
email_body = xitroo_session.get("https://api.xitroo.com/v1/mail?locale=en&id={}".format(email_id), data=data)
bodytext = re.findall('"bodyText":"(.*?)"', email_body.text)[0]
code = base64.b64decode(bodytext)
conv_email_base64 = base64.b64encode(code)
body = base64.b64decode(conv_email_base64).decode()
return body
def main():
first_name = names.get_first_name(gender='male') #Random first name, example john
last_name = names.get_last_name() #Random last name, example doe
email = first_name + last_name + random_email() + "@xitroo.com" #combines first and last names together plus adds email domain @xitroo.com, [email protected]
password = first_name + last_name + random_pass() #combines first and last names together plus adds random numbers to generate password
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("--log-level=3")
os.environ['WDM_LOG_LEVEL'] = '0'
chrome_options.add_argument(
'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36')
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
chrome_options.add_argument("window-size=500,500") #sets the chrome window size
if Headless == True:
chrome_options.add_argument('headless')
else:
pass
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://mega.nz/register")
while __name__ == '__main__': #checks if the button is clickable on chrome tab
try:
r = driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[2]/input").is_displayed()
if r == True:
break
else:
pass
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[2]/input").send_keys(first_name) #sends first name in text box in chrome
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[3]/input").send_keys(last_name) #sends last name in text box in chrome
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[5]/input").send_keys(email) #sends email in text box in chrome
driver.find_element(By.ID, "register-password-registerpage2").click() #clicks on the password box 1
driver.find_element(By.ID, "register-password-registerpage2").send_keys(password) #sends password in text box in chrome
driver.find_element(By.ID, "register-password-registerpage3").click() #clicks on the password box 2
driver.find_element(By.ID, "register-password-registerpage3").send_keys(password) #sends password-2 in text box in chrome
driver.find_element(By.XPATH,"/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[8]/div[1]/input").click() #element clicks
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[9]/div[1]/input").click() #element clicks
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/button").click() #element clicks
email_content = FetchEmail(xitroo_email=email, subject="MEGA")
url = re.findall('https://(.*?)\n', email_content)[0] #grabs url from email to seperate it
confirmation_url = "https://" + url #adds https:// to url to auth
driver.get(confirmation_url) #opens the auth link
while __name__ == '__main__': #checks if button is clickable
try:
r = driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[3]/input").is_displayed()
if r == True:
break
else:
pass
except:
pass
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/div[3]/input").send_keys(password)
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[2]/div[2]/div[1]/form/button").click()
time.sleep(3)
try:
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div/div[2]/div[5]/div/div[2]/div[2]/div").click()
except:
try:
time.sleep(2)
driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div/div[2]/div[5]/div/div[2]/div[2]").click()
except:
pass
- We still have some stuff to do but the Main program is Done.
I like to add a checker to check if the account is really done and the way i do that is to check if the web-page says the account generation is successful here is how i do that
while True:
if "Account Recovery" in driver.page_source: #checks if The Account Was successfully Done
saveaccount = open("accounts.txt", "a")
saveaccount.writelines("{}:{}\n".format(email, password))
saveaccount.close()
else:
pass
I hope you learned something new with this lesson, In the next lesson we will go more in depth about selenium and automation, the projects will get more interesting I might be using a battle.net gen or a discord gen next lesson, that would be instresting since thesse tools sell for money.
Im so exited to see your guys feedback on this lesson and what i can improve on, to give you guys the best automation information out there
BTC: 32qQwjQ18FF2GntAP8iPhkQ4UoMkgbTN4F
- Discord: Flex#8941
- Email: [email protected]