Published on

字体反爬

Authors
  • avatar
    Name
    Pony Ma
    Twitter

什么是字体反爬?

字体反爬是一种防止爬虫程序提取网页文本的技术。 字体反爬的原理是将网页文本中的字符映射到字体文件中的字形,然后通过 CSS 样式表将字体文件应用到网页文本中,使得爬虫无法直接提取网页文本内容。

字体反爬示例

可以看到HTML源代码中的内容和页面显示的内容是不一样的,这就是字体反爬的效果。 当爬虫程序爬取网页内容时,就只能获取到HTML源代码中的内容,那就是乱码数据,而无法获取到页面显示的真实数据。

字体反爬的原理

下面这段HTML就是上面例子中的源代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Custom Font Example</title>
    <style>
        @font-face {
            font-family: 'ShuffledFont';
            src: url('data:font/ttf;base64,AAEAAAAMAIAAAwBAT1MvMpPQvG4AAAFIAAAAYGNtYXBB40qpAAABvAAAAOxmdmFyluBpmwAACWgAAABsZ2x5Zg5ypHYAAAK8AAAGgmd2YXLV3Im7AAAJ1AAABKpoZWFkIqxLlAAAAMwAAAA2aGhlYQh0AvQAAAEEAAAAJGhtdHgEpwDHAAABqAAAABJsb2NhCRMHQwAAAqgAAAASbWF4cAAUAHAAAAEoAAAAIG5hbWUABgAAAAAJQAAAAAZwb3N0/4YAMgAACUgAAAAgAAEAAAACAQbE7b2FXw889QADA+gAAAAA3LAkpwAAAADi+eILACz/twO+A0IAAAAGAAIAAAAAAAAAAQAABIj+4AAAA+gALAAqA74AAQAAAAAAAAAAAAAAAAAAAAEAAQAAAAgAbwALAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAEA90AZAAFAAACigJYAAAASwKKAlgAAAFeADIBRQAAAgsCAAAAAAAAACAAAIMq3zwQAAAAFgAAAABBREJPAEACMb6oA3D/iAAABIgBIGAGAQcAAAAAAh8C3QAAACAABgPoADQAMAAvADAAMgAsADIAMwAAAAAABAAAAAMAAAAkAAAABAAAAHwAAwABAAAAJAADAAoAAAB8AAQAWAAAABIA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            font-family: 'ShuffledFont';
        }
    </style>
</head>
<body>
    <h1 class="custom-font">뺃뺨ȱᲸෟซ궺ᶕ</h1>
</body>
</html>

在了解字体反爬的原理之前,我们需要了解一些字体文件的基础知识。

字体文件的构成

我们可以在一些在线工具中查看和编辑字体文件,例如Font qqe2

字体文件通常由两部分组成:字形和字符映射表。

  • 字形:字体文件中的每个字符都对应一个字形,字形是字符的可视表示。
  • 字符映射表:字体文件中的字符映射表将字符映射到字形,以便在文本中显示正确的字符。
字体文件示例1
字体文件示例2

获取文字的Unicode编码

text = "测试文本"
unicode_text = [ord(char) for char in text]
print(unicode_text)

css font-face 应用字体

那么字体文件又是如何在浏览器中应用的呢?这就要用到CSS中的@font-face规则了。 @font-face规则通常用于指定自定义字体文件的 URL,以便在网页中显示特定的字体。

mdn web docs

<style>
@font-face {
  font-family: "Open Sans";
  src:
    url("/fonts/OpenSans-Regular-webfont.ttf") format("truetype"),
}

</style>
  • font-family:字体名称,用于在 CSS 中引用字体。
  • src:字体文件的 URL,可以是相对路径或绝对路径。
  • format:字体文件的格式,通常是 truetypewoff

如果实现字体反爬?

字体反爬的原理我们已经了解了,那么如何实现字体反爬呢?

字体反爬的实现

  1. 生成字体文件
  • 生成字体文件,将字符映射到不同的字形。
  • 可以使用在线工具或字体编辑器生成字体文件。

我实现了一个简单的字体混淆工具,font-obfuscator,欢迎大家star、fork、提issue。

我们使用font-obfuscator库生成混淆后的字体文件。

首先安装font-obfuscator

pip install font-obfuscator

使用示例:

from font_obfuscator import obfuscator_text

test_text = "这是一段测试文本"
obf_text, obf_io = obfuscator_text(test_text)

print(f"Origin Text: {test_text}")
print(f"Obf Text: {obf_text}")
print(f"Obf Font: {obf_io}")
test_html = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Custom Font Example</title>
    <style>
        @font-face {
            font-family: 'ShuffledFont';
            src: url('data:font/ttf;base64,ObfFont') format('truetype');
        }
        .custom-font {
            font-family: 'ShuffledFont';
        }
    </style>
</head>
<body>
    <h1 class="custom-font">ObfText</h1>
</body>
</html>
""".replace("ObfFont", obf_io).replace("ObfText", obf_text)
print(test_html)
  1. 将字体文件应用到网页
  • 使用 @font-face 规则将字体文件应用到网页中。
  • 在 CSS 中指定字体文件的 URL 和格式。
    <style>
        @font-face {
            font-family: 'ShuffledFont';
            src: url('data:font/ttf;base64,AAEAAAAMAIAAAwBAT1MvMpPQvG4AAAFIAAAAYGNtYXBB40qpAAABvAAAAOxmdmFyluBpmwAACWgAAABsZ2x5Zg5ypHYAAAK8AAAGgmd2YXLV3Im7AAAJ1AAABKpoZWFkIqxLlAAAAMwAAAA2aGhlYQh0AvQAAAEEAAAAJGhtdHgEpwDHAAABqAAAABJsb2NhCRMHQwAAAqgAAAASbWF4cAAUAHAAAAEoAAAAIG5hbWUABgAAAAAJQAAAAAZwb3N0/4YAMgAACUgAAAAgAAEAAAACAQbE7b2FXw889QADA+gAAAAA3LAkpwAAAADi+eILACz/twO+A0IAAAAGAAIAAAAAAAAAAQAABIj+4AAAA+gALAAqA74AAQAAAAAAAAAAAAAAAAAAAAEAAQAAAAgAbwALAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAEA90AZAAFAAACigJYAAAASwKKAlgAAAFeADIBRQAAAgsCAAAAAAAAACAAAIMq3zwQAAAAFgAAAABBREJPAEACMb6oA3D/iAAABIgBIGAGAQcAAAAAAh8C3QAAACAABgPoADQAMAAvADAAMgAsADIAMwAAAAAABAAAAAMAAAAkAAAABAAAAHwAAwABAAAAJAADAAoAAAB8AAQAWAAAABIAEAADAAICMQ3fDgscuB2Vrbq+g76o//8AAAIxDd8OCxy4HZWtur6Dvqj///3V8iLx9eNN4nJSSEGBQVsAAQAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAABwAAAAAAAAAAgAAAIxAAACMQAAAAYAAA3fAAAN3wAAAAEAAA4LAAAOCwAAAAAAABy4AAAcuAAAAAUAAB2VAAAdlQAAA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OTc1NCsM69/XzFBQsbFQULGx4Ccn4IM4OzvZ2Tc319f+/hUVBRw6SEdHR0dISUo+GO/e3t7e3t/m7ffm6eXm8RAuNysP80VF8+MzM+MrK/39gwCAAQAIALIAAAA/Cg0ZICUzMyYbGBoYEgP4+P8RIy4tJCAZEQgHChAdKdvjA88sJyUmJ8LEx8s0NMfH8fH2AwP2ryAnNkFDPigOBRXyxM09Oi8qsbfH8z4yJyQkIs/T2N7pgz9dXVpZVlVVVVdbX2JRI/Xm5uXl5eXl6uvt7+/v4tfYTlhd5CQjIiEg2trd4iUlJby8JTo60dEkEw8HAQMPNVllFVY6+x4dHRr39/rhJC08SVJUAwH57+aDAIABAAgA5AAAAD8c6+sc6Pz86AQNDQQDCAgDSUU0JCEW/OTd1vHt5ez5BAYMCv/z5jgoEgUA++fe397g1z8/Pz46Ni8R8efk3NfXLuL2CE9QV001Lx0I/gn/6eLaR0fa1Dw8PDo3NRr//P8FBwgLDgkA/P0WLisH4dTUgz8UFLe3JCTJyTIy0tIyMtPTz+cWO0Q4Fe/g3MC8Ojk1MTDR0dHQKc7JvbOvwfMECRckFRULAu/j4+wJJSwmGhEPLiQkJhII+Ovl9Bk9SUc+LBcD3ff3FRVFQjo6Ojo6Ojo9QCz76OTi4uLi4uLi+SVGgwCAAQAIAAYAAAIBAQIBDPEBPsCAAQAIAFYAAAAL8BAQ8P78/P7CPz/CQP95C+XtDi0yKArq3dGthkAAhwt6USUSBN++tMLsExuDJUNDzc0vL7m5Ghrn5xL38endz90AIi0yLh0SIztDPDAL5NPj8PX2gwAAAA==') format('truetype');
        }
        .custom-font {
            font-family: 'ShuffledFont';
        }
    </style>
  1. 在网页中使用自定义字体
  • 在 HTML 中使用自定义字体,例如在标题中使用自定义字体。
		<h1 class="custom-font">뺃뺨ȱᲸෟซ궺ᶕ</h1>

字体反爬的应用场景

  • 字体反爬可以有效防止爬虫程序、自动化工具获取网站的文字内容,提高网站的内容保护性。

字体反爬的局限性

  • 字体文件的大小较大,会增加网页的加载时间。
  • 字体反爬最终也是会被破解的,只能增加爬虫的难度,而不能完全阻止爬虫。