|  | 
  
		
		
300精币 
| class Sg_lsm: def __init__(self):
 self.session = requests.session()
 self.headers = {
 "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
 "Accept-Language": "zh-CN,zh;q=0.9",
 "Cache-Control": "no-cache",
 "Connection": "keep-alive",
 "Host": "captcha.luosimao.com",
 "Pragma": "no-cache",
 "Referer": "https://captcha.luosimao.com/demo/",
 "sec-ch-ua": "\"Chromium\";v=\"112\", \"Google Chrome\";v=\"112\", \"Not:A-Brand\";v=\"99\"",
 "sec-ch-ua-mobile": "?0",
 "sec-ch-ua-platform": "\"Windows\"",
 "Sec-Fetch-Dest": "iframe",
 "Sec-Fetch-Mode": "navigate",
 "Sec-Fetch-Site": "same-origin",
 "Sec-Fetch-User": "?1",
 "Upgrade-Insecure-Requests": "1",
 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
 }
 
 def get_img(self):
 url = "https://captcha.luosimao.com/api/reload"
 params = {
 "k": "95059ebc73a95c13d50ceb8e06939c94",
 "l": "zh-cn",
 "t": str(int(time.time() * 1000))
 }
 res = self.session.get(url, params=params, headers=self.headers)
 s = res.json()['s']
 print(s)
 
 url = "https://captcha.luosimao.com/api/frame"
 params = {
 "s": s,
 "i": "_8qm0156o3",
 "l": "zh-"
 }
 res = self.session.get(url, params=params, headers=self.headers)
 # print(res.text)
 data = re.findall('captchaImage = (.*?);', res.text, re.I | re.M | re.S)[0]
 p = re.findall("p:\['(.*?)'", data)[0]
 self.l = re.findall("l:(.*?)}", data)[0]
 self.l = json.loads(self.l)
 # print(type(self.l))
 self.img = requests.get(p).content
 # self.l为图片坐标数组 self.img为混淆图片 如何通过PIL还原 思路没理清楚
 
 
 | 
 
最佳答案
查看完整内容 from PIL import Image
def restore_image(l, img):
    # 创建一个与原始图像大小相同的新图像
    new_img = Image.new('RGB', (310, 155))
    # 打开原始图像
    img = Image.open(io.BytesIO(img))
    # 遍历 l 中的坐标
    for item in l:
        # 获取 x 和 y 坐标
        x, y = item[0], item[1]
        # 获取给定坐标处的像素值
        pixel = img.getpixel((x, y))
        # 在新图像中设置像素值
        n ... 回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区  可获得加分喔。友情提醒: 本版被采纳的主题可在 申请荣誉值  页面申请荣誉值,获得1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。快捷通道:申请荣誉值  →  |