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.")