python 爬虫搞定芝麻二维码识别

前言

上周再 QQ 群看到有小伙伴遇到二维码图片识别网址链接需求,而 RPA 产品并无直接支持的组件
本来我想搞个开发者,发部成组件,,算了就这吧。

芝麻二维码平台

该平台支持许多业务,有兴趣可自行了解
python 爬虫搞定芝麻二维码识别

研究一番、直接撸代码

import requests

def get_url(img_path):
    '''
    img_path : 图片:jpg、jpeg、gif、png 大小:小于2M 上传带二维码的图片路径
    return url : 解析二维码之后的网址链接
    '''
    # 获取图片后缀名(jpg、jpeg、gif、png)
    tempfilename = img_path.split('.')[1]
    headers = {
        "Host": "www.hotapp.cn",
        "Connection": "keep-alive",
        "Content-Length": "128843",
        "Origin": "https://www.hotapp.cn",
        "Referer": "https://www.hotapp.cn/jiema",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6776.400 QQBrowser/10.3.2601.400",
        "Accept": "*/*",
        "Referer": "https://www.iflyrec.com/html/addArtificialOrder.html",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN,zh;q=0.9",
        # "Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryZjPRjN0wAzGytw34",
        "Cookie": "Hm_lvt_291*****c6=***,*8; XSRF-TOKEN=********%3D; zhima_laravel_session=********%3D; Hm_lpvt_2911e7fbbc2af45ce5bee6f3e22033c6=1614934191"
    } # 根据浏览器设定请求头参数 
    files = {
             'name':  (None, '1.'+tempfilename), 
            "_token": "******",
             'file': ('1.'+tempfilename, open(img_path, 'rb'), 'image/'+tempfilename)
    } # 通过vue上传文件规则,对文件进行字节流上传并设定参数

    response = requests.post('https://www.hotapp.cn/qrcode/parse', headers=headers, files=files) # 发起post请求
    data = response.json() # 解析返回的json数据
    url =  data['text'] # 获取解码后的链接
    return url


效果展示

这里我选择对群二维码进行识别
python 爬虫搞定芝麻二维码识别

平台很给力,识别速度还挺好,结果也正常
python 爬虫搞定芝麻二维码识别