• selenium-python-验证码-滑动验证码


    from selenium.webdriver import Chrome
    from selenium.webdriver.common.action_chains import ActionChains
    import numpy as np
    import cv2
    import time
    import requests
    
    web = Chrome()
    
    web.get('https://dun.163.com/trial/sense')
    web.find_element_by_xpath('/html/body/main/div[1]/div/div[2]/div[2]/ul/li[2]').click()  #点击可疑用户-滑动拼图
    time.sleep(1)
    web.find_element_by_xpath('/html/body/main/div[1]/div/div[2]/div[2]/div[1]/div[2]/div[1]/div/div[2]/div[3]/div/div/div[1]/div[1]/span').click() #点击完成验证
    time.sleep(1)
    bg_img_src = web.find_element_by_xpath('/html/body/main/div[1]/div/div[2]/div[2]/div[1]/div[2]/div[1]'
                              '/div/div[2]/div[3]/div/div/div[2]/div/div/div[1]/div/div[1]/img[1]').get_attribute('src')
                            # 背景图
    
    front_img_src = web.find_element_by_xpath('/html/body/main/div[1]/div/div[2]/div[2]/div[1]/div[2]/div[1]'
                              '/div/div[2]/div[3]/div/div/div[2]/div/div/div[1]/div/div[1]/img[2]').get_attribute('src')
    
                            # 滑块
    
    with open("bg.jpg",mode='wb') as f:
        f.write(requests.get(bg_img_src).content)
    
    with open("front.jpg",mode='wb') as f:
        f.write(requests.get(front_img_src).content)
    
    
    import numpy as np
    
    bg = cv2.imread('bg.jpg')
    front = cv2.imread("front.jpg")
    
    
    # 灰度处理
    bg = cv2.cvtColor(bg,cv2.COLOR_BGR2GRAY)
    front = cv2.cvtColor(front,cv2.COLOR_BGR2GRAY)
    
    
    # 处理滑块
    front = front[front.any(1)]
    
    #匹配  图像匹配算法
    result = cv2.matchTemplate(bg,front,cv2.TM_CCOEFF_NORMED) # 精度最高,速度最慢
    
    # np.argmax(result)  # 返回一维位置
    
    x,y = np.unravel_index(np.argmax(result),result.shape)
    div = web.find_element_by_xpath('/html/body/main/div[1]/div/div[2]/div[2]/'
                                    'div[1]/div[2]/div[1]/div/div[2]/div[3]/div/div/div[2]/div/div/div[2]/div[2]')
    
    ActionChains(web).drag_and_drop_by_offset(div,xoffset=y,yoffset=0).perform()
    
    
    # print(x,y)
    # w,h = front.shape
    # cv2.rectangle(bg,(y,x),(y+w,x+h),(38,38,38),2)
    #
    # cv2.imshow("gray1",bg)
    # cv2.imshow("gray2",front)
    # cv2.waitKey(0)
    # cv2.destroyAllWindows()
    
    
    
  • 相关阅读:
    包含停用词的词频统计(map,set非class版本)<< 0919
    pair,map,set<<0924
    答题程序中用户登录状态的保存<<0924
    时间戳<<0923
    list,vector相关函数与区别<<0922
    类里面的赋值和拷贝函数<<0922
    vector的初始化补充,list,find函数,指针和迭代器等<<0922
    redhat 6上nis配置
    如何查看cache信息
    oprofile 安装使用
  • 原文地址:https://www.cnblogs.com/chenfei2928/p/12843630.html
Copyright © 2020-2023  润新知