0% found this document useful (0 votes)
60 views1 page

Extract Yopmail Code with Selenium

The document contains a Python script that uses Selenium to retrieve a verification code from a Yopmail inbox. It automates the process of entering an email, checking the inbox, and extracting the code from the email content using regular expressions. The script handles exceptions and ensures the browser is closed after execution.

Uploaded by

Bao Le
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views1 page

Extract Yopmail Code with Selenium

The document contains a Python script that uses Selenium to retrieve a verification code from a Yopmail inbox. It automates the process of entering an email, checking the inbox, and extracting the code from the email content using regular expressions. The script handles exceptions and ensures the browser is closed after execution.

Uploaded by

Bao Le
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

from selenium import webdriver

from selenium.webdriver.common.by import By


from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import re

def get_yopmail_code(email):
driver = webdriver.Chrome()
driver.get("https://www.yopmail.com/en/")

try:
# Nhập email
email_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "login"))
)
email_input.send_keys(email)

# Nhấn nút "Check Inbox"


check_inbox_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "#refreshbut button"))
)
check_inbox_button.click()

# Chuyển vào iframe để lấy nội dung email


iframe = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "ifmail"))
)
driver.switch_to.frame(iframe)

# Lấy nội dung email


email_content = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.TAG_NAME, "body"))
).text

print("Nội dung email:", email_content) # Debug để kiểm tra nội dung

# Tìm mã xác thực chính xác


code_match = re.search(r"This is your login code:\s+([A-Z0-9]{4,6})",
email_content)
if code_match:
return code_match.group(1)
except Exception as e:
print(f"Lỗi xảy ra: {e}")
finally:
driver.quit()

# Gọi hàm
email = "mcc_prod_067" # Thay bằng email của bạn
code = get_yopmail_code(email)
print(f"Mã xác thực: {code}" if code else "Không tìm thấy mã xác thực.")

You might also like