import base64
import json
import requests
headers = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'keep-alive',
'Cookie': 'ASP.NET_SessionId=dwgdziizfuk4gjxl0rxudunh',
'Host': 'gcxm.hunanjs.gov.cn',
'Referer': 'http://gcxm.hunanjs.gov.cn/dataservice.html?queryType=0&keyword=',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
def get_params(response):
# print(response.text)
if not response:
response = requests.get('http://gcxm.hunanjs.gov.cn/AjaxHandler/PersonHandler.ashx?method=GetVerifyImg',
headers=headers)
data = json.loads(response.text)[1]
# 2、base64解码
img = base64.urlsafe_b64decode(data)
ext = 'png'
# 3、二进制文件保存
filename = "{}.{}".format('hunan_bjt', ext)
with open(filename, "wb") as f:
f.write(img)
i_j = find_write(filename)
i = i_j[0][0]
code = json.loads(response.text)[2]
print(i, code)
return i, code
def find_write(file_name):
from PIL import Image
i_j = []
img = Image.open(file_name) # 读取照片
img = img.convert("RGBA") # 转换格式,确保像素包含alpha通道
width, height = img.size # 长度和宽度
for i in range(0, width): # 遍历所有长度的点
for j in range(0, height): # 遍历所有宽度的点
data = img.getpixel((i, j)) # 获取一个像素
if (data.count(255) == 4): # RGBA都是255,表示白色
i_j.append((i, j))
return i_j
if __name__ == '__main__':
response = requests.get('http://gcxm.hunanjs.gov.cn/AjaxHandler/PersonHandler.ashx?method=GetVerifyImg',
headers=headers)
get_params(response)
滑块验证拖动距离
最新推荐文章于 2023-07-22 23:49:57 发布