from seleniumimport webdriver
#selenium登录qq邮箱
#qq邮箱像人人网一样直接去找账号密码的输入框是不行的 因为标签全部写在loginform下
#破解方法一:用寻找text的方法直接寻找基本版
# d = webdriver.Chrome('./chromedriver.exe')
# d.get('https://mail.qq.com/cgi-bin/loginpage')
# d.find_element_by_link_text('基本版').click()
# d.find_element_by_id('u').send_keys('qq号')
# d.find_element_by_id('p').send_keys('密码')
# d.find_element_by_id('go').click()
# d_dic = d.get_cookies()
# abc = {dic['name']:dic['value'] for dic in d_dic}
# print(abc)
#破解方法二:窗口切换
d = webdriver.Chrome('./chromedriver.exe')
d.get('https://mail.qq.com/cgi-bin/loginpage')
d_qh = d.find_element_by_id('login_frame')#因为全部都在ifrom的标签底下所以我们需要 先找到的是ifrom这个标签
d.switch_to.frame(d_qh)#然后我们用切换语句切换到这个窗口底下在去找 如果直接去找的话是找不到的
d.find_element_by_id('switcher_plogin').click()
d.find_element_by_id("u").send_keys('qq号')
d.find_element_by_id("p").send_keys('密码')
d.find_element_by_id("login_button").click()
d_dic = d.get_cookies()
abc = {dic['name']:dic['value']for dicin d_dic}
print(abc)