ddddocr

复制代码
import requests


def aaa():
    cookies = {
        '__jsluid_s': 'fc5d7cb700e08b9891cdcf95030401fd',
    }

    headers = {
        'Host': 'weather.121.com.cn',
        'Connection': 'keep-alive',
        'Pragma': 'no-cache',
        'Cache-Control': 'no-cache',
        'sec-ch-ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
        'sec-ch-ua-platform': '"Windows"',
        'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
        'Sec-Fetch-Site': 'cross-site',
        'Sec-Fetch-Mode': 'no-cors',
        'Sec-Fetch-Dest': 'image',
        'Referer': 'http://weather.sz.gov.cn/',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
        'Cookie': '__jsluid_s=fc5d7cb700e08b9891cdcf95030401fd',

        'Host': 'weather.121.com.cn',
        'Connection': 'keep-alive',
        'Pragma': 'no-cache',
        'Cache-Control': 'no-cache',
        'sec-ch-ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
        'sec-ch-ua-platform': '"Windows"',
        'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
        'Sec-Fetch-Site': 'cross-site',
        'Sec-Fetch-Mode': 'no-cors',
        'Sec-Fetch-Dest': 'image',
        'Referer': 'http://weather.sz.gov.cn/',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
        'Cookie': '__jsluid_s=fc5d7cb700e08b9891cdcf95030401fd',

    }

    params = {
        'source': 'pc',
        'gdbsuser': '9c1bc19da29f4131bc4d3d6a26599559',
        'r': '1699018207264',
    }
    response = requests.get(
        'https://weather.121.com.cn/szqx/api/twt/kfr/gryy/code.do',
        params=params,
        cookies=cookies,
        headers=headers,
    )
    return response.content
复制代码
# encoding=utf8
# 识别验证码-GIF

from PIL import Image
import ddddocr

# 获取GIF的各帧
def getJpg(img):
    im = Image.open(img)
    imgs = []
    try:
        while True:
            current = im.tell()
            img = im.convert('RGB')

            # 可以将各个帧图片保存出来观察一下
            # img_path = 'pics/' + str(current) + '.jpg'
            # img.save(img_path)

            # 将获取的图片放到列表里面,给后面合成图片用
            imgs.append(img)
            im.seek(current + 1)
    except:
        pass
    return imgs

# 多张图片合成一张
def conflate(img_paths):

    cage = [] # 笼子,把图片放进来合并,如果有两张就合并,一笼不容二虎
    num = 0
    for img in img_paths:
        num += 1
        cage.append(img)
        if len(cage) == 2:
            merge = Image.blend(cage[0], cage[1], 0.5) # 合并两张图片,透明度0.5
            cage = [merge] # 合并完,重置笼子
    # 把合成完的图片保存出来,只是为了看看结果,后续直接用merge识别就行了
    merge.save("cage/intact.jpg")
    return merge

#识别验证码x
def ivd(img):
    ocr = ddddocr.DdddOcr()
    res = ocr.classification(img)
    return res

if __name__ == '__main__':
    from xxx import aaa
    from io import BytesIO
    imgs = getJpg(BytesIO(aaa()))
    merge = conflate(imgs)
    res = ivd(merge)
    print(res)
相关推荐
007php0074 分钟前
某大厂MySQL面试之SQL注入触点发现与SQLMap测试
数据库·python·sql·mysql·面试·职场和发展·golang
CodeCraft Studio5 分钟前
Excel处理控件Aspose.Cells教程:使用 Python 将 Pandas DataFrame 转换为 Excel
python·json·excel·pandas·csv·aspose·dataframe
flashlight_hi18 分钟前
LeetCode 分类刷题:2563. 统计公平数对的数目
python·算法·leetcode
java1234_小锋19 分钟前
Scikit-learn Python机器学习 - 特征预处理 - 归一化 (Normalization):MinMaxScaler
python·机器学习·scikit-learn
雨中散步撒哈拉27 分钟前
13、做中学 | 初一下期 Golang数组与切片
开发语言·后端·golang
0wioiw029 分钟前
Go基础(③Cobra)
开发语言·后端·golang
星空的资源小屋32 分钟前
网易UU远程,免费电脑远程控制软件
人工智能·python·pdf·电脑
楼田莉子37 分钟前
C++算法专题学习:栈相关的算法
开发语言·c++·算法·leetcode
IMER SIMPLE38 分钟前
人工智能-python-深度学习-神经网络-MobileNet V1&V2
人工智能·python·深度学习
晨非辰41 分钟前
#C语言——刷题攻略:牛客编程入门训练(九):攻克 分支控制(三)、循环控制(一),轻松拿捏!
c语言·开发语言·经验分享·学习方法·visual studio