163登录使用selenum登录,唯一需要注意的是需要先切到iframe标签内,才可以获取到form表单
直接上代码
# -*- coding: utf-8 -*-
# Time: 2020-06-22
# Author: luoshen
import time, traceback
from selenium import webdriver
def login():
"""
登录163邮箱
"""
acount_num = input("请输入账号:\n")
password_num = input("请输入密码:\n")
driver = webdriver.Chrome()
url = "http://mail.163.com/"
driver.get(url)
time.sleep(10)
elem = driver.find_element_by_xpath('//div[@id="loginDiv"]/iframe')
# 切换到iframe
driver.switch_to.frame(elem)
# 用户名
acount = driver.find_element_by_name('email')
acount.clear()
acount.send_keys(acount_num)
# 密码
passwd = driver.find_element_by_name('password')
passwd.clear()
passwd.send_keys(password_num)
# 点击登录
time.sleep(3)
click_button = driver.find_element_by_id('dologin')
click_button.click()
time.sleep(5)
print(driver.get_cookies())
if __name__ == '__main__':
login()
![点击并拖拽以移动 wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==](https://i-blog.csdnimg.cn/blog_migrate/a4f5b03f7b6a50bacba1c5c0559c367e.png)
为了方便观察,采用的有界面登录方式,登录成功后,可以设置为无界面模式。