script 3
script 3
import imaplib
import email
def accept_cookies(driver):
try:
cookie_button = driver.find_element(By.XPATH,
"//button[contains(text(), 'Accept')]" or "//button[contains(text(),
'Aceitar')]")
if cookie_button.is_displayed():
cookie_button.click()
except Exception as e:
try:
driver.get("https://visa.vfsglobal.com/ago/en/prt/login")
time.sleep(3)
password_field = driver.find_element(By.CSS_SELECTOR,
"#password")
login_button = driver.find_element(By.XPATH,
"//button[@type='submit']")
username_field.send_keys(credentials['username'])
password_field.send_keys(credentials['password'])
login_button.click()
time.sleep(5)
except Exception as e:
try:
if otp_field:
otp_field.clear()
otp_field.send_keys(otp_code)
otp_field.send_keys(Keys.RETURN)
except Exception as e:
try:
mail = imaplib.IMAP4_SSL("imap.gmail.com")
mail.login(email_user, email_password)
mail.select("inbox")
mail_ids = messages[0].split()
# Obter o e-mail
if isinstance(response_part, tuple):
msg = email.message_from_bytes(response_part[1])
if isinstance(subject, bytes):
if "OTP" in subject:
if msg.is_multipart():
if part.get_content_type() == "text/plain":
body = part.get_payload(decode=True).decode()
otp = extract_otp(body)
return otp
else:
body = msg.get_payload(decode=True).decode()
otp = extract_otp(body)
return otp
print("Nenhum e-mail com OTP encontrado.")
return None
except Exception as e:
return None
def extract_otp(body):
import re
# Função principal
def main():
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
login_credentials = {
'username': "[email protected]",
'password': "suasenha"
gmail_credentials = {
'email_user': "[email protected]",
'email_password': "suasenhaouappsenha"
}
login(driver, login_credentials)
# Aceitar cookies
accept_cookies(driver)
otp_code = get_otp_from_gmail(gmail_credentials['email_user'],
gmail_credentials['email_password'])
if otp_code:
handle_otp(driver, otp_code)
else:
driver.quit()
if __name__ == "__main__":
main()