快手爬虫,解决粉丝数,关注数等字体加密!python快手爬虫

941 阅读1分钟
![](https://p6-tt-ipv6.byteimg.com/large/pgc-image/4854fcad06424a1cb5358d6054296436)

想拿一下粉丝数 关注数 描述等
发现字体是加密的 elements是这样的

![](https://p6-tt-ipv6.byteimg.com/large/pgc-image/315d8fa6720b4da297c972d0265fcf61)

源代码里是这样的

![](https://p26-tt.byteimg.com/large/pgc-image/3a91234adf8c4ff48d0d40f6ac3a1e1e)

找了找js 原来是用


1

这些玩意 去

![](https://p26-tt.byteimg.com/large/pgc-image/c250647c0eb845f082199bf327a2f098)

这个ttf里一一对应 然后用 js + css画出来的
找到问题所在,就fuck掉它
把js扣出来?用execjs去执行?太LOW了
既然做python 那就用python去重写
首先用re去拿这个ttf的url (因为每次都变)

![](https://p26-tt.byteimg.com/large/pgc-image/55e68933f6ef4f509bba0570112a6971)

先给这玩意下载下来 把这个ttf文件扔fonteditor里 然后去
fontstore.baidu.com/static/edit…
瞅瞅

![](https://p26-tt.byteimg.com/large/pgc-image/aad0ca19660041d7aa400af596a93474)

这个时候就发现了东西

![](https://p6-tt-ipv6.byteimg.com/large/pgc-image/93dcaf1eedde466e9fe1b9c88f9f7199)
![](https://p1-tt-ipv6.byteimg.com/large/pgc-image/0ac60b797d1e4b2190f73b60c07d5655)

不就是这玩意吗,找到对应关系了 那就ok了
TTF文件没办法直接搞啊 ?怎么办
保存成xml !

![](https://p26-tt.byteimg.com/large/pgc-image/906ae2f6a0174acb8b8507f0bafc4b19)

然后就成了这玩意 ok对应关系也有了 python也能搞了

去写一下 整逻辑就是
先去拿 ttf文件 url 请求url 保存 然后转xml
然后 拿加密前的特殊字符

# 就是这玩意

12

然后去切割 对应 OK完事
对应关系的代码
根据看到的 id : 0啥也不说
从1~15 就是这些东西

![](https://p26-tt.byteimg.com/large/pgc-image/702f0ba553c548b28668b0fa497e48de)

上代码

# 对应关系 

def kuaishou_un_font(soup, font_size):
	# soup 就是传的 ttf转码成xml的
    font_dict = {}
    for font_m in soup.glyphorder.children:
        if font_m != '\n' and 'humans' not in font_m:
            id = font_m.get('id')
            name = font_m.get('name')
            if id != '0' and int(id) < 11:
                font_dict[name] = str(int(id)-1)
            elif id == '11':
                font_dict[name] = '.'
            elif id == '12':
                font_dict[name] = 'w'
            elif id == '13':
                font_dict[name] = 'k'
            elif id == '14':
                font_dict[name] = 'm'
            elif id == '15':
                font_dict[name] = '+'

    size_dict = {}
    for font_k in soup.cmap_format_4.children:
        if 'map' in str(font_k):
            code = font_k.get('code')[-4:]
            name = font_k.get('name')
            size_dict[code] = name
    return font_dict[size_dict[font_size]]

然后是拿TTF 文件然后转成xml

# TTF转XML
 font = TTFont('font_size.ttf')
  font.saveXML('font_size.xml')

和split后list去一一解密

# font_url 自己去动态拿 每次都变动
font_url = ''
font_res = requests.get(font_url)

  with open('font_size.ttf', 'wb+') as f:
      f.write(font_res.content)

  font = TTFont('font_size.ttf')
  font.saveXML('font_size.xml')
  soup = BeautifulSoup(open('font_size.xml'), 'lxml')
  try:
      fan = user_data_json['obfuseData']['fan'][40:-8].split(';&#x')
      fans = ''
      for f in fan:
          fans += kuaishou_un_font(soup, f)
  except:
      fans = ''

最后

![](https://p9-tt-ipv6.byteimg.com/large/pgc-image/2204b80f31a9426c8d05fe8b30b454cd)

OK~ 解码完成 全部代码没放 因为是根据需求写的 懒得改成大家都能用的了 主要是给个思路 思路有了就很简单 需要的找我

大家可以批量paqu!

此文转载文,著作权归作者所有,如有侵权联系小编删除!

原文地址:blog.csdn.net/qq_41367883…

完整项目代码获取点这