selenium+python实现自动登录脚本

作者:nice_xp 时间:2021-09-30 01:36:19 

os:windows

前提:Python,selenium,IEDriverServer.exe,ie浏览器

首先安装Python2.7

安装成功后,计算机联网状态下在cmd命令行下输入:pip install -U selenium

selenium安装后,在selenium官网下载IEDriverServer.exe

将IEDriverServer.exe放到ie浏览器的安装目录下:C:\Program Files (x86)\Internet Explorer,并将该目录添加到计算机的环境变量中

测试webdriver:

在Python命令行下敲入命令:


from selenium import webdriver
webdriver.Ie()

ie被打开后并显示:This is the initial start page for the WebDriver server表示成功

自动化登录源码:


from selenium import webdriver
import time

driver=webdriver.Ie()
#登录xxx.com
driver.get("http://XXXX.com")
#等10秒,浏览器打开和网页跳转需要时间
time.sleep(10)

#取ID为txtLoginCode的网页元素(用户名输入元素)
elem_user=driver.find_element_by_id('txtLoginCode')
#清空输入
elem_user.clear()
#键入用户名
elem_user.send_keys('nice_xp')
#取ID为txtPwd的网页元素(密码输入元素)
elem_pass=driver.find_element_by_id('txtPwd')
#清空输入
elem_pass.clear()
#键入密码
elem_pass.send_keys('*****')
#取ID为btnLogin的登录按钮
elem_login=driver.find_element_by_id('btnLogin')
#点击登录按钮
elem_login.click()

exit(0)

来源:https://blog.csdn.net/nice_xp/article/details/54915566

标签:自动,登录,脚本,selenium,python
0
投稿

猜你喜欢

  • 教女朋友学Python3(二)简单的输入输出及内置函数查看 <font color=red>原创</font>

    2022-11-14 08:32:18
  • Python Flask-Login模块使用案例详解

    2021-10-14 21:01:17
  • Python requests模块cookie实例解析

    2023-11-18 15:44:56
  • Python中pyecharts安装及安装失败的解决方法

    2021-01-13 06:00:52
  • SQL Server用触发器强制执行业务规则

    2009-01-20 16:05:00
  • CSS背景图片的运用优化HTTP连接数

    2008-09-04 21:38:00
  • MySQL 5.0默认100连接数的修改

    2008-11-05 13:34:00
  • 实用301转向到另一域名相应页面的asp代码

    2011-04-18 10:42:00
  • asp如何刪除客户端的Cookies?

    2010-05-18 18:25:00
  • Python的Web框架Django介绍与安装方法

    2021-03-06 05:46:12
  • 经验总结:ASP与存储过程解析

    2008-11-07 13:33:00
  • python 读txt文件,按‘,’分割每行数据操作

    2022-11-11 08:04:17
  • Python去除PDF水印的实现示例

    2022-08-13 19:26:45
  • tensorflow使用L2 regularization正则化修正overfitting过拟合方式

    2023-11-26 04:07:32
  • WEB界面设计五种特征

    2010-03-16 12:34:00
  • PHP autoload使用方法及步骤详解

    2023-08-22 13:05:44
  • 微信公众平台开发入门教程(图文详解)

    2023-06-21 11:10:05
  • 深入理解python中的闭包和装饰器

    2023-03-20 06:27:48
  • 9种python web 程序的部署方式小结

    2021-04-14 10:39:44
  • 想用户所想(感受亚马逊的设计)

    2007-08-26 17:09:00
  • asp之家 网络编程 m.aspxhome.com