python破解验证码操作

  • Post author:
  • Post category:python




python破解验证码操作

仅供大家研究

import pdb
import time
from hashlib import md5
import requests
from PIL import Image
from webdriver_helper import *
from selenium.webdriver.common.by import By
def f(driver):
    driver.save_screenshot('a.png')  # 截取整个DOC
    driver.find_element(By.XPATH,'//*[@id="loginName"]').send_keys('2236001404397')
    driver.find_element(By.XPATH,'//*[@id="password"]').send_keys('Ouchn@2021')

    img = driver.find_element(By.XPATH, '//img[@src="/am/validate.code"]')
    print(img.location)  # {'x': 684, 'y': 301}
    print(img.size)  # {'height': 36, 'width': 100}

    left = img.location['x'] + 150
    top = img.location['y'] + 80

    right = img.location['x'] + img.size['width'] + 250
    bottom = img.location['y'] + img.size['height'] + 100

    photo = Image.open('a.png')
    photo = photo.crop((left, top, right, bottom))

    photo.save('full_uams.png')
    time.sleep(3)


class Chaojiying_Client(object):
    def __init__(self, username, password, soft_id):
        self.username = username
        password =  password.encode('utf8')
        self.password = md5(password).hexdigest()
        self.soft_id = soft_id
        self.base_params = {
            'user': self.username,
            'pass2': self.password,
            'softid': self.soft_id,
        }
        self.headers = {
            'Connection': 'Keep-Alive',
            'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
        }

    def PostPic(self, im, codetype):
        """
        im: 图片字节
        codetype: 题目类型 参考 http://www.chaojiying.com/price.html
        """
        params = {
            'codetype': codetype,
        }
        params.update(self.base_params)
        files = {'userfile': ('ccc.jpg', im)}
        r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
        return r.json()

    def PostPic_base64(self, base64_str, codetype):
        """
        im: 图片字节
        codetype: 题目类型 参考 http://www.chaojiying.com/price.html
        """
        params = {
            'codetype': codetype,
            'file_base64':base64_str
        }
        params.update(self.base_params)
        r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, headers=self.headers)
        return r.json()

    def ReportError(self, im_id):
        """
        im_id:报错题目的图片ID
        """
        params = {
            'id': im_id,
        }
        params.update(self.base_params)
        r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
        return r.json()

if __name__ == '__main__':
    driver = get_webdriver()
    driver.get(
        r'https://iam.pt.ouchn.cn/am/UI/Login?realm=%2F&service=initService&goto=https%3A%2F%2Fiam.pt.ouchn.cn%2Fam%2Foauth2%2Fauthorize%3Fservice%3DinitService%26response_type%3Dcode%26client_id%3D345fcbaf076a4f8a%26scope%3Dall%26redirect_uri%3Dhttps%253A%252F%252Fmenhu.pt.ouchn.cn%252Fouchnapp%252Fwap%252Flogin%252Findex%26decision%3DAllow')
    driver.implicitly_wait(10)
    f(driver)


    chaojiying = Chaojiying_Client('15822051161', 'liuchen0726', '934550')  # 用户中心>>软件ID 生成一个替换 96001
    im = open('full_uams.png', 'rb').read()  # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
    print(chaojiying.PostPic(im, 1902))  # 1902 验证码类型  官方网站>>价格体系 3.4+版 print 后要加()
    print(chaojiying.PostPic(im, 1902)['pic_str'])
    driver.find_element(By.XPATH, '//*[@id="validateCode"]').send_keys(chaojiying.PostPic(im, 1902)['pic_str'])
    driver.find_element(By.XPATH,'//*[@id="button"]').click()

    pdb.set_trace()





版权声明:本文为weixin_53439312原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。