码迷,mamicode.com
首页 > 其他好文 > 详细

58同城 字体反爬理解...和猫眼不同

时间:2019-06-29 22:20:49      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:asto   ble   dpcp   key   自定义   ttf   group   pat   ict   

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

url = https://gz.58.com/zufang/?utm_source=market&spm=u-2d2yxv86y3v43nkddh1.BDPCPZ_BT&PGTID=0d100000-0000-31f5-5967-5384271a3920&ClickID=2
headers = {
    User-Agent:Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)
}
response = requests.get(url=url,headers=headers)
# 获取加密字符串
base64_str = re.search("base64,(.*?)‘\)",response.text).group(1)
b = base64.b64decode(base64_str)
font = TTFont(io.BytesIO(b))
bestcmap = font[cmap].getBestCmap()
newmap = dict()
for key in bestcmap.keys():
    value = int(re.search(r(\d+), bestcmap[key]).group(1)) - 1
    key = hex(key)
    newmap[key] = value
    
    
# 把页面上自定义字体替换成正常字体
response_ = response.text
for key,value in newmap.items():
    key_ = key.replace(0x,&#x) + ;
    if key_ in response_:
        response_ = response_.replace(key_,str(value))


rec = etree.HTML(response_)
lis = rec.xpath(//ul[@class="house-list"]/li)
for li in lis:
    money = li.xpath(.//div[@class="money"]/b/text())[0]
    if money: 
        print(money)

和猫眼不同,猫眼是把编码对象在glyf         而58则是在cmap中

 

 

https://www.cnblogs.com/eastonliu/p/9925652.html

58同城 字体反爬理解...和猫眼不同

标签:asto   ble   dpcp   key   自定义   ttf   group   pat   ict   

原文地址:https://www.cnblogs.com/zengxm/p/11107972.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!