这几天,在家有点闲的慌,就想找点事做,这不,就像使用python脚本实现自动登录Google邮箱。
首先,我们都知道,说到python自动化就想到自动化测试,然后就是selenium模块,好了,你已经掉坑里面了。
有过经验的小伙伴都知道,在使用selenium时候,发现在浏览器上方会出现
这表示,你使用的操作已经被chrome浏览器发现了,然后浏览器就会阻止你的某些操作,比如登录google邮箱,会出现如下情况:
这时候,就算你换Edge、fireFox也是一样的情况。
这是因为我们在使用selenium模块时被浏览器检测到了,
那么,有没有办法不被浏览器检测到呢?有的,请往下看
这里我们或用到undetected_chromedriver模块
第一步:安装undetected_chromedriver
pip install undetected_chromedriver
第二步:实现google邮箱自动登录
import undetected_chromedriver as uc
# import selenium.webdriver as uc
from selenium.webdriver.common.by import By
import time
driver = uc.Chrome() #change for your path
# 打开Gmail登录页面
driver.get('https://mail.google.com/')
# 找到用户名输入框并输入用户名
username_input = driver.find_element(value='identifierId')
username = 'XXX@gmail.com' # 替换成您的Gmail邮箱地址
username_input.send_keys(username)
time.sleep(10)
# 点击“下一步”按钮 VfPpkd-vQzf8d
next_button = driver.find_element(value='identifierNext')
next_button.click()
time.sleep(10)
# 你的邮箱密码
password = "password"
password_input = driver.find_element(by=By.NAME, value='Passwd')
password_input.send_keys(password)
time.sleep(10)
# 点击“下一步”按钮
next_button = driver.find_elements(by=By.TAG_NAME,value='button')
next_button[1].click()
time.sleep(30)
# 退出
driver.close()
driver.quit()
现在,自动登录google邮箱的功能你已经实现了!!!
来尝试以下吧! 顺便留下你的足迹----点赞+关注!!!