1. 程式人生 > 實用技巧 >Python3 爬蟲-自定義字型反爬

Python3 爬蟲-自定義字型反爬

 1 <html>
 2     <head>
 3         <title>new font</title>
 4         <meta charset="utf-8" lang="zh">
5 <style> 6 @font-face { 7 font-family: 'new_font'; 8 src: url('Font/f1c26632.woff') //谷歌 9 } 10 .new_font { font-family: "new_font"; } 11 </style> 12 </head> 13 <body> 14 <
div> 15 <span class="new_font">新的字型格式:舒&#xf4c7;&#xebcc;</span> 16 </div> 17 </body> 18 </html>
  • 頁面顯示正常,但是通過開發者工具檢視則不正常
  • 獲取網頁使用的自定義字型檔案,可以使用百度編輯器進行檢視
 1 # 把上圖轉換為下圖,unie573轉換為58739
 2 FONT_DICT = {58739: '1', 58275: '2', 63321: '
3', 63537: '4', 58042: '5', 59755: '6', 59348: '7', 63702: '8', 60197: '9', 61011: '0',} 3 def get_font_w(content): 4 if len(content) == 0: 5 return '' 6 content = str(content).replace('&#', '0') 7 # 例如 <span class="new_font">新的字型格式:舒&#xf4c7;&#xebcc;</span> 8 # 如何獲取該內容,這是個問題<span class="new_font">新的字型格式:舒&#xf4c7;&#xebcc;</span> 9 for key in FONT_DICT.keys(): 10 key_16 = hex(key) 11 initstr = str(key_16) + ';' 12 content = content.replace(initstr, str(FONT_DICT[key])) 13 # <span class="new_font">新的字型格式:舒適型</span> 14 print(content)