Contents

安居客字体解密

Contents

:::tip 安居客网页价格字体加密问题 :::

问题

由js生成的fangchan-secret自定义字体,每隔几秒钟变化fangchan-secret的key。

https://gitee.com/chen-zq/bgimages/raw/master/img/20201105160943.png?imgslim

解决

根据网址获得的fangchan-secret的key来解码

https://gitee.com/chen-zq/bgimages/raw/master/img/20201105161250.png?imgslim

bs64_str是网页内容正则匹配到的key:

bs64_str = re.findall("charset=utf-8;base64,(.*?)'\)", html_str)[0]
from io import BytesIO
from fontTools.ttLib import TTFont
import base64

def get_page_show_ret(mystr, bs64_str):
    '''
    :param mystr: 要转码的字符串
    :param bs64_str:  转码格式
    :return: 转码后的字符串
    '''
    font = TTFont(BytesIO(base64.decodebytes(bs64_str.encode())))
    c = font['cmap'].tables[0].ttFont.tables['cmap'].tables[0].cmap
    ret_list = []
    for char in mystr:
        decode_num = ord(char)
        if decode_num in c:
            num = c[decode_num]
            num = int(num[-2:]) - 1
            ret_list.append(num)
        else:
            ret_list.append(char)
    ret_str_show = ''
    for num in ret_list:
        ret_str_show += str(num)
    return ret_str_show