想抓取一个验证码却显示乱码应该怎么恢复呢,求大神指导

各位大神,我想看一个验证码的响应,但是打开出来是乱码,应该怎么还原成图片呢

import requests
import base64
import io
import matplotlib.pyplot as plt
from PIL import Image
def http_get(url):
    print ('请求地址:{}'.format(url))
    '''
    '''
    headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel ) Gecko/20100101 Firefox/58.0'}
    resp = requests.get(url,headers=headers) #请求
    print('请求完成')
    if not resp:
        #print '无响应内容'
        return
   # print '响应:\nencoding={}'.format(resp.encoding)  #如果中文乱码,如果requests没有发现http headers中的charset
    resp.encoding='gbk' #设置响应编码(gbk、utf-8、gb2312)
    img_name ='1.png'
    with open(img_name, "wb") as f:
        f.write(resp.content)
    with Image.open(img_name) as img:
        plt.imshow(img)
        plt.show()
http_get('https://zjy2.icve.com.cn/api/common/VerifyCode/index?t=0.7431959431634945')

 

验证码是图片形式的,如果你要写一个验证码,直接用c#的图像对象生成就行了。 不明白你抓取的是什么样的验证码

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632