Python GUI自动化实现绕过验证码登录

yipeiwu_com6年前Python基础

这篇文章主要介绍了python GUI自动化实现绕过验证码登录,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

1. 获取cookies  

实现代码如下:

import time
from selenium import webdriver

class cookies_login:
  wd=webdriver.Chrome()
  def getCookies(self):
    wd=self.wd
    wd.maximize_window()
    #登录成功跳转后的页面
    url = "http://47.108.47.47:81/admin"
    #登录页面
    wd.get("http://47.108.47.47:81/admin/login?company=9")
    while True:
      print("please login")
      time.sleep(3)
      while wd.current_url == url:
        cookies=wd.get_cookies()
        wd.quit()
        return cookies

2. 绕过验证码登录

实现代码如下:

from selenium import webdriver
import time
from xctest_selenium.get_cookies import *
class NoSignLogin:
  def get_nosignlogin(self):
    cookies=cookies_login().getCookies()
    wd=webdriver.Chrome()
    wd.maximize_window()
    wd.implicitly_wait(20)
    # 登录成功跳转后的页面
    wd.get("http://47.108.74.74:81/admin#datacount")
    for cookie in cookies:
      wd.add_cookie(cookie)
      time.sleep(3)
    wd.refresh()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

详解Python利用random生成一个列表内的随机数

首先,需要导入random模块: import random 随机取1-33之间的1个随机数,可能重复: random.choice(range(1,34)) print得到...

浅谈python 里面的单下划线与双下划线的区别

在学习Python的时候,很多人都不理解为什么在方法(method)前面会加好几个下划线,有时甚至两边都会加,比如像 __this__ 这种。在我看到上面的文章之前,我一直以为Pytho...

Pytorch 实现自定义参数层的例子

注意,一般官方接口都带有可导功能,如果你实现的层不具有可导功能,就需要自己实现梯度的反向传递。 官方Linear层: class Linear(Module): def __in...

Python 查看list中是否含有某元素的方法

用关键字 in 和not in 来 如下: qwe =[1,2,3,4,5] if 2 in qwe: print ‘good!' else: print ‘not goo...

Python求两个list的差集、交集与并集的方法

本文实例讲述了Python求两个list的差集、交集与并集的方法。分享给大家供大家参考。具体如下: list就是指两个数组之间的差集,交集,并集了,这个小学数学时就学过的东西,下面就以实...