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

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

转载于:https://www.cnblogs.com/zengxm/p/11107972.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值