pycharm一些快捷键:

‘ ctrl ’ +‘ / ’ :注释

‘ Tab ’ :同时缩进

‘ shift ’ +‘ Tab ’ :左移 一次缩进

本文webinfo.txt路径:C:\Python27\New Folder\case\webinfo.txt

userinfo.txt路径:C:\Python27\New Folder\case\userinfo.txt

webinfo内容:

url=https://mail.163.com/
account_name=email
pwd_name=password
login_id=dologin
logout=退出
relogin=relogin

userinfo内容:

uname=songping0914 pwd=qaz123456
uname=songpingzi66 pwd=songping66

usedate.py:

 1 #!/usr/bin/python
2 # -*- coding: UTF-8 -*-
3 # 这个程序 将webinfo 和 userinfo的内容读进来并转化为指定字典,列表
4 import codecs
5 def get_webinfo(path):
6 web_info = {}
7 config = codecs.open(path,'r','utf-8') #
8 # 有汉字的时候用
9 #config = open(path)
10 for line in config:
11 #result = line.split('=') 这样结尾会有 \n
12 result = [ele.strip() for ele in line.split('=')] #列表解析
13 web_info.update(dict([result])) #列表转化为字典 更新到webinfo中
14 return web_info
15
16 def get_userinfo(path):
17 user_info = []
18 config = open(path)
19 for line in config:
20 user_dict = {}
21 result = [ele.strip() for ele in line.split(' ')] #列表解析 ['uname=songping0914', 'pwd=qaz123456']
22 for r in result:
23 account = [ele.strip() for ele in r.split('=')] #列表解析 ['uname', 'songping0914'] ['pwd', 'qaz123456']
24 user_dict.update(dict([account])) # {'uname': 'songping0914', 'pwd': 'qaz123456'}
25 user_info.append(user_dict)
26 return user_info
27
28 if __name__ == '__main__':
29 webinfo = get_webinfo(r'C:\Python27\New Folder\case\webinfo.txt')
30 # for key in webinfo:
31 # print(key,webinfo[key])
32 userinfo = get_userinfo(r'C:\Python27\New Folder\case\userinfo.txt')
33 # for l in userinfo:
34 # print(l)
35 # print (userinfo)
36 print userinfo
37 print webinfo

autologin代码:

 1 #!/usr/bin/python
2 # -*- coding: UTF-8 -*-
3 from selenium import webdriver
4 from selenium.webdriver.support.ui import WebDriverWait
5 from time import sleep
6 from usedate import get_webinfo,get_userinfo
7 import codecs
8
9 #自动登入163邮箱
10 def openBrower():
11 webdriver_handle = webdriver.Chrome()
12 return webdriver_handle
13
14 def openUrl(handle,url):
15 '''load url'''
16 handle.get(url)
17 handle.maximize_window()
18 sleep(3)
19
20 def findElement(d,args): #定位登入页面输入框和登入按键的元素
21 '''1:login_name
22 2 account_name
23 3 pwd_name
24 4 login_id'''
25 # if mailid in args:
26 ele_account = WebDriverWait(d, 10).until(lambda d:d.find_element_by_name(args['account_name']))
27 ele_pwd = d.find_element_by_name(args['pwd_name'])
28 ele_login_btn = d.find_element_by_id(args['login_id'])
29 return ele_account,ele_pwd,ele_login_btn
30
31 def sendVals(eletuple,arg): # 将用户名密码输入到 以上元素位置
32 '''eletuple: 输入框 ,arg = each = userinfo_list {account :uname pwd}'''
33 listkey = ['uname','pwd']
34 i = 0
35 for key in listkey:
36 #eletuple[i].send_keys('')
37 eletuple[i].clear()
38 eletuple[i].send_keys(arg[key])
39 i+=1
40 eletuple[2].click()
41 sleep(2)
42
43 def logout(d,args):
44 d.find_element_by_link_text(args['logout']).click()
45 sleep(2)
46 d.find_element_by_class_name(args['relogin']).click()
47 sleep(2)
48
49 def get_ele_tmes(d,times,fun):
50 return WebDriverWait(d,times).until(func)
51
52 def login_test():
53 d = openBrower()
54 webinfo_dict = get_webinfo(r'C:\Python27\New Folder\case\webinfo.txt')
55 openUrl(d,webinfo_dict['url'])
56 d.switch_to.frame("x-URS-iframe")
57 ele_tuple =findElement(d,webinfo_dict)
58 userinfo_list = get_userinfo(r'C:\Python27\New Folder\case\userinfo.txt')
59 '''
60 webinfo_dict = {'url': 'https://mail.163.com/', 'login_id': 'dologin', 'account_name': 'email',
61 'pwd_name': 'password','logout':u'退出','relogin':'relogin'}
62
63 userinfo_list = [{'uname': 'songping0914', 'pwd': 'qaz123456'}, {'uname': 'songpingzi66', 'pwd': 'songping66'}, {'uname': 'songpingzi0914', 'pwd': 'songping66'}]
64
65 '''
66 #
67 for each in userinfo_list:
68 sendVals(ele_tuple,each)
69 logout(d,webinfo_dict)
70 sleep(3)
71 # openUrl(d, webinfo_dict['url'])
72 # d.switch_to.frame("x-URS-iframe")
73 # d.find_element_by_name("email").clear()
74 sleep(3)
75 d.quit()
76
77
78 if __name__ == '__main__':
79 login_test()

错误提示:

selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document

最后,第一次登入后退出,第二次登入不能进行,还未修改成功,有知道的大神请指点,修改,不甚感激

PS 附上自动发邮件的脚本:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
from selenium import webdriver
from time import sleep
url1='https://mail.163.com/'
url2='https://mail.126.com/'
account1='songping0914'
password1='qaz123456'
account2='songpingzi66'
password2='songping66'
driver = webdriver.Chrome()
driver.maximize_window() #最大化
driver.get(url1)
sleep(2) #切换到表单
driver.switch_to.frame("x-URS-iframe") #
driver.find_element_by_name("email").clear()
driver.find_element_by_name("email").send_keys(account1)
driver.find_element_by_name("password").clear()
driver.find_element_by_name("password").send_keys(password1)
driver.find_element_by_id("dologin").click()
sleep(2)
driver.switch_to.default_content()
driver.find_element_by_xpath(".//*[@id='_mail_component_70_70']").click()
sleep(2)
driver.find_element_by_class_name("nui-editableAddr-ipt").clear()
account3='songpingzi66@126.com'
driver.find_element_by_class_name("nui-editableAddr-ipt").send_keys(account3)
sleep(2)
driver.find_element_by_css_selector("div[id^='_mail_input_3']>input.nui-ipt-input").send_keys(u"测试webweb")
af = driver.find_element_by_class_name('APP-editor-iframe')
driver.switch_to.frame(af)
driver.find_element_by_xpath('//body[@class="nui-scroll"]').send_keys("Good study, day day up!")
driver.switch_to.default_content()
driver.find_element_by_css_selector("div[id^='_mail_button_2']>span.nui-btn-text").click()

python selenium 多账户自动登入163邮箱的更多相关文章

  1. 网络爬虫之requests模块的使用+Github自动登入认证

    本篇博客将带领大家梳理爬虫中的requests模块,并结合Github的自动登入验证具体讲解requests模块的参数. 一.引入:   我们先来看如下的例子,初步体验下requests模块的使用: ...

  2. Ubuntu获取root 权限,开机自动登入root

    新机器获取root权限,只需要给root 增加密码: sudo passwd root 修改开机自动登入: #sudo gedit /etc/lightdm/lightdm.conf 修改参数: au ...

  3. Ubuntu输入密码之后,桌面闪一下黑屏,然后又返回到输入密码界面。但是其他账户可以登入

    1)原因:主目录下的.Xauthority文件拥有者变成了root,从而以用户登陆的时候无法都取.Xauthority文件 说明:Xauthority,是startx脚本记录文件.Xserver启动时 ...

  4. 利用WebBrowser实现自动登入功能

    公司内部改革,对考勤方面做出调整,要求实现办公自动化,在OA进行上下班考勤:作为程序员,突发奇想如何实现自动化考勤应用? 需求如下: 可设置考勤地址.用户信息.上下班时间: 根据设置的上下班时间,定时 ...

  5. ssh自动登入

    公司的服务器在国外,所以测试的查看日志的时候需要测试机,然后继续ssh 非常不方便,所以编写一个简单的ssh登入脚本 #!/usr/bin/expectset timeout 3spawn ssh n ...

  6. java web实现在cookie中保存用户名和密码,用户自动登入

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  7. python基础篇---实战---用户登入注册程序

    一.首先了解需求: 1.支持多个用户登入 2.登入成功后显示欢迎,并退出程序 3.登入三次失败后,退出程序,并在下次程序启动尝试登入时,该用户名依然是锁定状态 二.文件代码如下: f = open(& ...

  8. python+ selenium 实现简历自动刷新

    本文用到的文件的下载地址 百度网盘链接: https://pan.baidu.com/s/1wIda-wUz4X_Ck72xgZ6Ddg 提取码: etaa 1 安装Python 和 selenium ...

  9. MY_使用selenium自动登录126/163邮箱并发送邮件

    转自:https://www.cnblogs.com/yin-tao/p/7244082.html 我使用的是python2.7.13+selenium ps:几天之前,我曾多次尝试写这段代码,但是在 ...

随机推荐

  1. [atARC111F]Do you like query problems

    (以下修改指1和2类操作,询问指3类操作,操作指修改或询问) 注意到总方案数确定,那么不妨求出答案的期望,再乘上方案数即为答案 (这里从期望的角度考虑只是为了描述方便,并没有太大的实际意义) 设$E( ...

  2. CSharp使用Thrift作为RPC框架入门(一)

    前言 本文将介绍由 Facebook 开发的远程服务调用框架 Apache Thrift,它采用接口描述语言定义并创建服务,支持可扩展的跨语言服务开发,所包含的代码生成引擎可以在多种语言中,如 C++ ...

  3. 【知识详解】JAVA基础(秋招总结)

    JAVA基础 目录 JAVA基础 问:面向过程(POP)和面向对象(OOP)? 问:Python和Java的区别? 问:java的八大基本数据类型? 问:封装继承多态说一下? 问:方法和函数的区别? ...

  4. 洛谷 P3721 - [AH2017/HNOI2017]单旋(LCT)

    洛谷题面传送门 终于调出来这道题了,写篇题解( 首先碰到这样的题我们肯定要考虑每种操作会对树的形态产生怎样的影响: 插入操作:对于 BST 有一个性质是,当你插入一个节点时,其在 BST 上的父亲肯定 ...

  5. Navicat 激活教程2021(Linux)

    Navicat 激活教程2021(Linux) 目录 背景 环境 激活 清理 使用 背景 Navicat 是香港卓软数字科技有限公司生产的一系列 MySQL.MariaDB.MongoDB.Oracl ...

  6. Machine Learning读书会,面试&算法讲座,算法公开课,创业活动,算法班集锦

    Machine Learning读书会,面试&算法讲座,算法公开课,创业活动,算法班集锦 近期活动: 2014年9月3日,第8次西安面试&算法讲座视频 + PPT 的下载地址:http ...

  7. 标准非STL容器 : bitset

    1. 概念 什么是"标准非STL容器"?标准非STL容器是指"可以认为它们是容器,但是他们并不满足STL容器的所有要求".前文提到的容器适配器stack.que ...

  8. .net与java建立WebService再互相调用

    A: .net建立WebService,在java中调用. 1.在vs中新建web 简单修改一下Service.cs的[WebMethod]代码: using System; using System ...

  9. Mybatis批量添加、更新小结

    虽然是很基础的东西,不过难免会忘记,所以写个笔记巩固一下,顺便分享. 实体类: @Data public class EventOrder { ​ private Long id; ​ private ...

  10. 分布式事务(3)---强一致性分布式事务Atomikos实战

    分布式事务(1)-理论基础 分布式事务(2)---强一致性分布式事务解决方案 分布式事务(4)---最终一致性方案之TCC 前面介绍强一致性分布式解决方案,这里用Atomikos框架写一个实战的dem ...