32

css字体通用反爬

 3 years ago
source link: https://studygolang.com/articles/30443
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

css字体反爬通用方案

在爬大众点评的时候 我们也许会遇到下面这种情况, 我们看到的信息明明是正确的,爬虫拿下来就是乱码了 我们打开开发者模式

yyuEbaQ.png!mobile

image.png

发现源码就是乱码的

查看css

V7r6fa3.png!mobile

image.png

我们把这个css style取消

RjqEbuB.png!mobile

image.png

这下问题找到了 是css 使用的font文件做了手脚.

将字符的对应font文字图像成正确的信息

Qfeqeqj.png!mobile

image.png

从上图看 就是在字体文件内  的字体就是工(字体图像)

找到问题了, 我们现在用golang读取字体文件 读取对应编码的文字 将文字写入一个图像内, 使用tesseract识别出结果,不就可以了.

代码写完编译成dll文件以供python直接使用,在golang我查找了很多资料 并没有找到直接读取woff字体文件的解决方案,woff转tff需要重新造轮子,这部分暂时使用python实现,

源码已经放在github,自取学习研究

https://github.com/luopeixiong/universal_font_anti_aliasing

第一我们来找到woff文件地址

eyaIBzq.png!mobile

image.png

打开css引用

JvYJfav.png!mobile

image.png

我们找到了woff地址

https://s3plus.meituan.net/v1/mss_73a511b8f91f43d0bdae92584ea6330b/font/85226b1a.woff

需要反混淆的文字 这里我直接复制了

丙232

将2个参数传入anti函数,我们来看看运行结果

In6vQzz.png!mobile

image.png

输出了 工人体育场东路丙2号中国红街3号楼2层里

检查结果正确. 完美收工!

欢迎大家star.支持支持

目前字体文件只支持ttf以及woff格式, 目前支持所有用字体文件实现的css反爬.

有疑问加站长微信联系

iiUfA3j.png!mobile

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK