全球塑胶网 -- 字体解密

在线字体工具:https://font.qqe2.com/

import re
import requests
from io import BytesIO
import base64
from fontTools.ttLib import TTFont
from hashlib import md5
from lxml import etree



num_map = {
    "1bdedca4c1b334ff44b48cee9ebc9d25": 0,
    "016d2eabcd82820965b9a9260faa3c60": 1,
    "6f69c42f92df489924481239412bafe5": 2,
    "b801b0838ac2efa3e2098bd6812d94a4": 3,
    "03ca22e6117f8054b446e12721470d7d": 4,
    "c157d99699da62db396c421b5198482d": 5,
    "7904a363f6bf50deade01f9d00e669e8": 6,
    "c3f27c9de97215575859dd9cd9e2c46a": 7,
    "d66aa02aedf21dd6b6c0bdc7576da86c": 8,
    "eca05d0e93693afc0381da14248818c4": 9,
}


def handle_ttfont(data):
    font = TTFont(BytesIO(base64.b64decode(data)))
    font.save('font.ttf')
    font.saveXML('font.xml')

    font_map = {}
    for glyf in font.getGlyphOrder()[1:]:
        if glyf:
            coordinates = font['glyf'][glyf].coordinates
            coordinate_md5 = md5(str(coordinates).encode('utf-8')).hexdigest()
            key = '&#x' + glyf.lower() + ';'
            print(f'"{coordinate_md5}": {key}')
            num = num_map.get(coordinate_md5)
            if num is not None:
                font_map[key] = num
    # 返回字体映射
    return font_map

# 힑휆줇휆줇힑
# 18 4 529491
# 18040529491

# {'&#xd791': 1, '&#xe409': 2, '&#xf804': 3, '&#xd706': 4, '&#xf079': 5, '&#xa310': 6, '&#xf824': 7, '&#xe594': 8, '&#xc907': 9}


if __name__ == '__main__':
    url = 'https://yiqi1888.51pla.com/contact.htm'
    # url = 'http://www.whhxswkj.com/contact.htm'

    r = requests.get(url=url)
    content = r.text
    print(r.text)
    with open('font.html', 'w') as fl:
        fl.write(r.text)
    font_re = re.search(r";base64,(.*?)'\)", r.text)
    # font_re = re.search(r";base64,(.*?)\)", r.text)
    if font_re:
        font_str = font_re.group(1)
        font_map = handle_ttfont(font_str)
        print(font_map)

        for k, v in font_map.items():
            if k in content:
                content = content.replace(k, str(v))

    html = etree.HTML(content, parser=etree.HTMLParser(encoding='utf-8'))
    phone_str = html.xpath('//a[@class="encrypt"]/text()')[1]
    print(phone_str)
    # phone = ''
    # for char in phone_str.split(';'):
    #     phone += font_map[char]
    # print(phone)
posted @ 2022-05-31 17:26  二二二狗子  阅读(225)  评论(0)    收藏  举报