python 实现 自动登录+点击+滑动验证码验证

写这个小程序的原因很简单,哈哈,我要给支持的明星送花。就是网易星闻下的巨星势力榜,如下图所示(以胡歌为例):

点击右下角的花朵即可送一朵花,左上角显示当前剩余数量,规则是每两分钟花朵数量恢复成100,每个账号可以一直送。如果仅仅是点击花朵形状可以一直送花的话,是很简单的,关键问题在于它时不时会跳出滑动验证码,如下图所示,这时候就需要解决验证码的问题了,当然了,这部分代码我是参考的别人的。

需要做的准备工作比较多,需要用到的库有selenium、PIL、openCV库,还需要安装Chrome浏览器驱动,具体如何安装我就不详述了。需要注意一下,安装OpenCV大家还是去(https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv)下载.whl格式的文件再pip install,不然会像我一样走许多弯路... auto_click.py代码如下:
from selenium import webdriver
from selenium.webdriver.common.by import By
from PIL import Image, ImageEnhance
from selenium.webdriver import ActionChains  
from selenium.webdriver.common.keys import Keys  
from selenium.webdriver.support import expected_conditions as EC  
from selenium.webdriver.support.wait import WebDriverWait   
import cv2
import numpy as np
from io import BytesIO
import time, requests

class CrackSlider():
    """
    通过浏览器截图,识别验证码中缺口位置,获取需要滑动距离,并模仿人类行为破解滑动验证码
    """
    def __init__(self):
        super(CrackSlider, self).__init__()
        # 实际地址
        self.url = 'http://3g.163.com/wap/special/newsapp_idol_personal/?starId=14#/home'
        self.driver = webdriver.Chrome()
        self.wait = WebDriverWait(self.driver, 20)
        self.zoom = 2

    def open(self):
        self.driver.get(self.url)

    def get_pic(self):
        time.sleep(2)
        target = browser.find_element_by_class_name("yidun_bg-img")
        template = browser.find_element_by_class_name("yidun_jigsaw")
        target_link = target.get_attribute('src')
        template_link = template.get_attribute('src')
        target_img = Image.open(BytesIO(requests.get(target_link).content))
        template_img = Image.open(BytesIO(requests.get(template_link)
  • 15
    点赞
  • 126
    收藏
    觉得还不错? 一键收藏
  • 19
    评论
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值