python 爬虫之字体反反爬
爬虫常用来从某些网站抓取数据, 包括文字,图片等都可能作为爬取目标。通常情况下, 文字数据有更高的价值, 更容易进行后续分析, 所以有些网站就将关键数据以图片, 或者自定义字体形式来展示, 这样一来, 爬虫拿到的数据就会难以分析, 分析成本增高, 收益减少, 就可以降低爬虫制作者的积极性。对于图片, 由于网站需要保证正常用户的体验, 所以不会有太低的识别度, 用普通的ocr即可拿到真实文字数据, 而对于自定义字体形式的反爬措施, 爬虫往往拿到的是一堆我们难以直观分辨出意义的"乱码", 只有与特定的字体文件对照, 才能明白其意义, 所以我们就需要做三件事:
- 下载字体文件
- 分析字体文件, 确定编码和文字的对应关系
- 根据对应关系,完成转换
对于1, 简单情况下, 只需要找到@font-face, 直接通过其src字段指向的链接就可以得到字体文件, 但是更多的网站是不会采用这种方式的, 因为这种方式只要弄到一份字体文件, 确定一次映射关系, 爬虫就畅通无阻了, 根本无法提高爬取成本, 所以大多数网站是用 src: url("data:application/octet-stream;base64, *******")这种64位编码形式来传输字体文件给浏览器的, 这样就可以对每一个页面使用不同的字体文件(主要是不同的映射关系)。对于这种情况, 我们只需要对其base64字符串解码, 得到二进制码即可
1 import base64 2 from io import bytesio 3 from fonttools import ttlib 4 5 6 class fontparser: 7 def __init__(self, b64str): 8 self._font = ttlib.ttfont( 9 bytesio(base64.b64decode(b64str) 10 )
对于2, 简单情况下, 网站每次传输的字体文件中编码文件与字体形状(也就是文字)对应关系是不变的, 复杂情况下, 同一编码可能对应不同的字体形状, 为了应付这种情况, 我们只能寻找字体形状与文字的映射关系, 在通过编码确定特定的文字形状来完成映射。这里我用实习僧的字体举例:
首先打开实习僧上任意一个详情页, 检查源代码,检索@font-face, 将其src中的64位编码字符串拷贝下来,
然后使用fonttools将其保存为xml文件
1 ttlib.ttfont( 2 bytesio(base64.b64decode(b64str) 3 ).savexml('./font.woff')
然后打开该xml文件, 可以看到其结构大致如下:
其中cmap是编码与字体形状的映射关系, glyf是字体形状信息。那么只需要把glyf中的字体形状与特定的文字对应起来就完成了第一阶段的任务, 这里需要借助
这里我只用到了数字, 所以只列举了一部分:
1 _glyph_map_ = { 2 'uni30': 0, 'uni31': 1, 'uni32': 2, 'uni33': 3, 3 'uni34': 4, 'uni35': 5, 'uni36': 6, 'uni37': 7, 4 'uni38': 8, 'uni39': 9, 5 }
对于3, 这里给出针对实习僧数字部分字体转换的简单例子
1 import base64 2 from io import bytesio 3 from fonttools import ttlib 4 5 6 ## 实习僧字体解析器 7 class sxsfontparser: 8 # 字体形状与文字映射关系 9 _glyph_map_ = { 10 'uni30': '0', 'uni31': '1', 'uni32': '2', 'uni33': '3', 11 'uni34': '4', 'uni35': '5', 'uni36': '6', 'uni37': '7', 12 'uni38': '8', 'uni39': '9', 13 } 14 # 样品字体 15 _sample_font_str_ = ''' 16 d09grgabaaaaaciqaasaaaaao+waaqaaaaaaaaaaaaaaaaaaaaaaaaaaaabhu1vcaaabcaaaadmaaabcsp6z7u9tlziaaae8aaaaraaaafztbmsmy21hcaaaayaaaao0aaaj3gjr9tznbhlmaaafnaaahlgaacfusfawzghlywqaacomaaaamqaaadywqtgpaghlyqaai8aaaaagaaaajbcpblfobxr4aaaj4aaaalqaaagqufp/mmxvy2eaacsuaaaaygaaamr1ieq+bwf4caaajwaaaaadaaaaiaf4af9uyw1laaalgaaaavcaaakfkahoc3bvc3qaacbyaaabuaaaa4pwd99uejxjygrgyobikgpqywb0cfmjyebgyggaajamy05meijqdmodyrgaaq4gzooiagckiwnpahicy2bk/cg4gygvgynvmd2fgygxckkzcjk0mo1kygbiygvmwaoc0lxtgbwykr7/4yj/+4lhm0c5kwrqmbekbwdmmwxzejzd1stvfauax/fvpdyxatvqw98ckio+w63ptlqxlb5buostisekxdhwioeibwgjb+begiqqeuagb0xomgysubjgaglcodc7293uzu60ne7ulirq/c2//g+a7ubt7mxpp/p7/wabu4ffsklqdbicomofl+hs3z3zi7j/zvn6rymo/+evguhja9atdatng0vblsbkbuztsj1o3uy3phvt/emh9lb09syuzmhmyfho8yhxi9nu7jbscpzarif3incmd2giy6i/35hvyh/lv/jjivoofubczwffobgohufdkbaq3ih2fuekmekt0qrs3tkr0vfsowqpuqk10yfonlo6uxly/+s5qrvto1nnp5un98vl403xnvhwpbypxxmzl8tryplypbkuelsbq6ur15pwpc1zmwxidia7k0pjqwrmdmx27vztxdhcuzkf8kptwhbcu3yldsxhif94npvo5jne4i4e5bu6eijn+zy1peuhs1lmd4/ymx+zus16uy2rp5plvmf6wvmrr3mxn1jfe3zkk3zgd2ptm2v4kj95gn9zxko8xjt8wju8tbtf8rfp8zdrujcmfuupnucehumlxudvvuvjpurtxmca9/mexlar4y/wdj/wa1+o8y0m0sjvtnovy2j4l8pwp3ktrv2p/3v+al1snaevgpsy7jfbgonoe5w3zydgkiknbfdmuscitakhtdgufvi7tkkhddquh1i3tuki3wlkfoleu7pi95tyrnrildjs20zzi73dleiyu0x5jhpqlewyj00zzbztlfbgb6z2xxm/aeow2w5tlslumawa7lap32svmzjorsguexintoknd8zqz6xcbas9myy6tn1got/uevknpr6qb7lapcofm3wifmxujvkjqvcumqaguaiaukzhztq6wmwm/hh2mzpiogjqjogqqz2er009jryx2nm2lji6s3jd1gkkxay+uxwxnztixtrxirdmbae0ytr7sntnc0dpigklkb03rqklsmkfinpns0huzdomorwm9sa6ynorolhtohbdnw0lk5tnk8pkftpemhnotdxmrtbtefojpjvi6qxpl5huni0u0/tmw0w81lraxjtm+0w8x7rkxidnm0y8bfo34jhtzhhpmrapmcum7ao8xrscldomparcms0jlxwmjaqsmnasarnpn6noq/1gql43bsljq2lvsdpm+0qy0rs0jbtmm0uy02q/w5ldph0mowrazjjtpm0mmtgtnlnjpr1mds7o/xfexco8ejxtwgtcvnx2pmufxyai8syhkcptdamzb0rirehehfwkmiuzqyuzrswfpesercmhihgseqhhi0ilqi6ieika77yepgzgiepcu0ycmbp473nmqo+9f+d35swczuyz93p837fwlggggexl/bkhhjbmgmrryyldjib+o98gu7lxbw/gkrfjghsbrulqa8o4u9gp0iel6xywaqk9eevfi2ibpavqpi9hsa8uq4wxg9fgg5ad74ufkpxki4ybavboi/gyixjmcdaobxmnp62s0xizyq6weg+yvzmrwlrbql9vvtelpttzvhdcqkp2cndtalqqfydhb6iaryu3xhghzq0bcnrngr+/e+7o9g78grtugimnf1mzn9cc23ztub7easevowk8upaxddwlxymtyl+rsvg6a1sutmrl0ka2vomechsgc/t+5iu20n/inpfxw7v4+1d5rt+23sytvt/gt/plm4bd/3kmejwbw+dsa7povodzvzi744xnbpk42wz03snckjpnwn3w3vapazwtsmmrdnaxfmaltzajvusb31sxjeosp6ak8nep5g9kjuzx8th02v7/egey56uk44yhpphmayot3lbpqlslk+xonjvu3ntldpa2hds4p5joxczxfo6bhxaiehfp38l98hi5nwv/dubxa52/4c3qyx/ootzwytzo3oiahfxr0ezkrtput0p/z3cqrsmzw2d1azop9xn+6v/hb+otn3vxlrwbrhvzxdivnqwxfvpxzjkfeyjleo5fql/4o16c5tct+v73kub4rloxohrfrwqoky9fomsrggyeuinso+reest+jkfgpftv/rg+gj/3dcow8vyi6pwcmynm4/shhhq1h9kznk0d5+7mobhxbhlqjg7owqbmme0w6vawccco3mzfysbe0j9chggoyviwnh93ai34w9wmd8rzj9+/t/vne6wih3prsppih9dqydimwj+85r03mhcswpuphsl5n7z928pyj5djz93kattbwvugztkogzw/bcw3b/thjhugvedsh4qs/ouhqqbg/hodokzbn79avrx087rkik3vlz+pgkjwjaqzrnq7wbo3yqxorh8n51ly/derv/6lachwii72dcka9ttbroqwgwd2jrpgtg/evpwildiujkdkh08awzs6pjhq2jrqspxyptpr0c/0dztmbmdlm7gnh9zzvwqgwfybaxu7oe1szbjlhxr1cp4spolqwyjveceqtdcnogaclw5eotnyauy7ikthwm8lpfpufhzjm/qiqbgr3avujjin1v8d9is/kvrvkwgu7vrhuny7jwavodmrtah0zi+8i5vwzjxxw5j+wqlxpfafp54b4w6hf6aled4h2oifsyg1zfmx58lntnoivwha56+kfmeljx0vzrl0igeflzfhcwpvbya2qf4xuxh6ebomtejqkrj6n4anl3lfcduferqp1ujafmls+ehvzejchy8x8gqzg524tblt0novhiraursxzcabwwqx0vjaxrpqiadxwmru7alefh6vhsg7ugokensmz13ku+akvbozbv5wzr/9o2jnw7i4alom4kaivbbnfdkqulptmbmdf4dc3zv6gsge3svbi0brl/mheqhbakjsf1bx1nn1e7rxb7zgphog19sryk3wsjjol8y0wx6gd80a1o8rv0puicf3xa0pcstrzcat9kx8pnejmthhwqpfjeflziqzlmyka0pblywm1o32ts4cnzngigtblxuetrwpjrf7sjryt0dsqbcs8pdzerhyby3vol9zvm7dhvyvuipg5hmkugtxchjew0f28dp2tj5rvzjvvbpkveu+0znfrzewnrlhsupzydnthsadyrtkkcdi6y5focjanohzelzsd5lfbaqrgy9z2tulzuadlpengf1giz4wlrfmhrrmqwceb1hjz1b+vgg86rckjcqguw/lmjhvoif9jd7buoanqjs8grqmk4gtdbrgcfggurybe1b3mqiqf8nh1pt9oegvdbugxoynfyskhk00kwokmvmvgzkwrcnp3ju6yj3iqai0ndw1oa2qduhx29hdvksxqaopmfzzk4y9rg6m07hbzladtumoufg7ols/kt4kditbrw4ykzhilxb2lo0thbzsxx6wkujvt1nbwemlrom/z8unydloc+60kbtltesp9elrudpcda+qv3ek/jmocmbd7ilr7+lqsj8p+teqt/xepy0py6w0yxlnt+9ovlkwngxdze8qwxbrq3klf5rt0adz4cecgnnxfgnvebh34c1hfc7er7eiy/g5hgqii+hgmzy7ek+nlhjxhgw6ok2kt24z3m5ry23asimyiywsxydfdt3ppqd38xifs/eyd4xn2shbwih9+rdv5q3znhqbmkt509njzat5bvbvaedsvhv8wpdnuim8jx4urt35rqv/sgdhiyuvxfcemsts6dgkocyk9lrykfjscxyom87p0vfwc2g40qcwee/rtxpanmaahgliqpgwjokjymikgqyoyupg2xckogxfjqvg5wjouqwnxivsubb3pry7eqrykym92mpzgvipftj3nh6gdhycajtjqsjwsgmyw6oivumo3sjgqhuwvgeibhkbue5jswcps7ryuipfvhpofuryw1ikmah4dyfeycgaa7wjhvqw+eaf2ce/y4fojp2pw1pyf7kydixwnogzxdeuytravrg+3njb13df2o76ddrgjvitc1kkrofbcyvhqav4zocvel6hoqh86utlk8n22edtoabrhs5emqwnrzwv1skl3smlfwrckph0yzzlwkk21sneiig8qsxyszxpkcgvhxkfnlud3sw7bw3dwltl0oqifsnexih9k0p0cdmvwceqt27cabaoaah1s5ishctt4wss7fjdzuwkctqri0ay0pizo1ne3ehsedgukcymor9b3hy4ncgqo3dxt7hftqmxdzcjatqmdhfz6bssvl3i4qktfxjbb48x6gxmncepfc38psl2a4yz0fezxc4rbafkjozsgvutew1pqf5eyrcxlxmwmkoz8vk0a9wpjxondepqtbocnesjj1ethlvwwq0dpd8a1mgluzyfvk0vqf0gjttwn4cneozgxrqy0zjlw/03jh/4+afpzxz/ofgnzjsr+elgradnoxausn3huhfql8o0dnisqt800ovgoukfnopgjy9fuvdghkmuqtlabrxfmobkxh0xcowsmbsonbccdzuluimzcweyyyajhexy5jp62qocdzdxqrlr8aafksnc8ekrld7fwcj2pbmntmtx1gsfybzbwqr7h3iyvla7sbj6qgyrw4qfd7zlqozy2dvhl+pk+dlbch5fs/ej5cij4ed+yetjg8cuooadj6w2qhawelpyo3uehgrc0ihszqygf3hrssqatc1sz7uefx4rfdqrnatnb02+yhfbz1yja20eahwggk/kra8q7hrgtdhemd8nq7ldwnk0c0m1gfe+blv8zis7n6nttn5d4skeenclopiqfpfk0ytn6aqubjqxavowgckqcckl4g0np5jqwfmfslfykozttsbrom8d8sjsdgilzc+o1zlxfvmunltcqfqxqqokkhq06wkp2vfmhxf5jrcypyxl0f/4c/99/v+pfpuhjtxluvsassrfwoxdf/fnpfbi3jrw2xtg9ox9p57+0jz+nxsrvqejm3qcfukhwtg7cwpz7a7xt5rwxhsmw8tatv9taecswz7zl1j/gckrk9gxxp4ygx6uei8q5d4jwzb09xslnldi9x3zttws0wfsnthfxpkgzkh3v0z9bstjvi00fxnn6ejcbbmxfxjywevxs/emvevsioahangzseamoivtzhjfz8vrfgvgehdwfnesjo6owlab24+58e7xt7ytozj682+wbj/romm/nonrxjz4k/glzhmjemkxlewkksx108ijrmiovkhofd6iy3ptzh6aovujdsjhonci+s3dk5nugqcxsypprvposwpm4wmgnnltwjcucx+oa+i71p6c4mj29azcogg1bsf7ebvnqdwwgub2vev+rsus0ybajnyn8zklgaonxiboevuy5oujfgbgqlfol5/ocgs6lmwkfvt3vhytcpsduail/oooilcrr8ltrfuq5twgbrwb1xlmnh0xdtbymdd+35lmsbwklc+yncbnfjwknmyayweby+exgq/uknqe1ykot6k5fpoqh8hoxojayfeenttxssdn8og6hsi8edpzab4jcqky2bt2apeyw2tc0boyeybwq6bnoiih2t4fbwunvbktw7wmntpvczkr2ugcmqha0zllrqt6dilb+h62r4wlncilylxcnjhf5dnhmfcu3ejwcjdyncsy3jeja+fxtfml5hjfzjuwqjuhcyzlgu1wft7owo4syt7wmjd0v0utx0gxq2gqtktkpivme1baomgy2mbx7dhkvsn3vu6xzdynovovoculndvls2lnc2kvk+b8kgbc1uixtofgubpjpkd4qar/wnrbxcapzg2koluocmczzxwylcbbuizifzo/sqo9atkmjay1wumq5manax+wkjcx8ud64z72zreieq4b+4japhu3hylncyfi6ukdonrycnigpfwuc4lfrefwepgy1t4/hbrkrngsv9oaekwhnppfjanfachddsy4a1s2abivjawiim2h7+dptu0/gd3+gzuqnnwko7xanpabzqjwl4nl78z1npntn9cr17f0hlnk83d29hkxp9kbun7dvapvxxvwgf69sqxygiouupz+7t4vohu+hkrybw3pneukwu0xvikhkk1j8lltpva/xlsac3ezypk5pvrq1uacaiu3ddunochipfgc7e3dgjj2csbshddhezyo7xgxk/epviyn4fdvxpkd7ioucpspbrrjpbza81pqx9cle5sywgmapo29vkwyvvkun4exr7j1goy4qdye2ctuoeuxsutoxodb2a1ljhdbsitkhs3ckbb9jngpxrxtlpgawtuqkkwr6vm8w9kuidedk6jt14ktjnh04f1ebshr4biycessj1xe8rqencvhphm5szys1guayv4mhitlsmlgabxkurrjefuqrnwi+tfg0qlstwpgplkcdci+swhcsl6tjbcdq/zvi6viyu9hkhpgid7jj5bscexq7s+4uvupllppct9ltrgr9nlu+7u7mulqchpgocjbjvindbjipey8pgdj8dzff2in6yfv0igxwi6bmikqviv4hb+b6eabppsdqszpgawie6bsav4ponvqv2pucozyxatwlquo/yjrtqfenua72kg76dwytwr1qjcist9cvxj59sxz63pxfapv3en7lo2qvqxrm/d88cgxse16e2vs9vksdzuykpak6dbtyxyx2xxy8oi5m/54907lqcgdpddptcfxfr4pgtu50etrpxyowuk0/pkxxvbdh1fu+dukhxeim5qvtmu8+os8mxzngdro7trke0dlqlh7grcvyf0bkdxlweusndu4pzuxd/rzfw9drms6qhsfoo29vktxnrs/7uxxhxbgg8r7geaeetvzbhlsznrj6ueubxa+sxrx3ful3+nmptmp8hrslxaw1lfjtx0kc8phkx6d6wxhite3sm2r4wqnphodn7kmwy6cwlvajkmqampj8wpatxj14c6xgb0/80vdmtdkshrgbpcbxl5hqddsz1/hph1eh7uh6gi5j6xwz1aeywujeczu3rj/nl6cp8giamm7n1t9dgznjxv9o0f9d2zgjw1zwo3mqx1ztb4w73pl6fhjgfp/edrq2lpjrfl4witsi6k0kly7lea9uwxintnfb3bbvm6d/qwehlovv821ted1xtj9e+cxonhnlh7p4ckoevcctp6blo4v1hriahr9rvm1nwdlh/h/duv/kzkxzjlazctnwxvotcfi4igrryijeetyylgdbrf3upe1l851jonkiv+hmdf1u6rwplaa/ef4qmp9pa5gr9urr6pqaqoqdphhqeyehmfwluqxcqkbp3tpz9jacw3inol03immjhqvvhk0aieixrws1cleywt2/5h0wf3sb3wb16z9pnfvy/khmh607kn/99ufotofitqyaoveqqdj4z6mcppe8e7rt88oxycqsdwlkt6gnitjsmgd7ifoqidwnbxkzxgsq18r1p68bmlbckp7vuuxfeyqmw4uzldnwvghtg4x/s3fgu96hgzmzacaf/qi8wlinaz1gkkfyqwtxo5mqkqcysd1d2whkh0s8lx8+deprfrvrbdedz548ovnzczvwbnwhjaidnu0rejiqgnofhdpcgelholn/byhi/4/bb2menlcqgmrqmywj0rmsm3gtnlet7tg0q4ykunslrxpt+mswahovy2rgzldirbxddbyyxmtm4nw0mbfdpwpfhnqhx9q746x+0ds20nrb6pxlmppk6sog3snwjrbjjsqocyxd8tuvq2wdvwly4zadhpt2nuwhtdgw0jqexbrh3wk9kepdncr86x2qhq+plerdsyenfkd36ucvpy+xbia5ql7u9cotf0jtryu7tieccehit5ilq2qdrhsj4ikgb973dbzkeur3uyehwdq6ez/lipmgnmemnzcy7yyysjoitut5a6itd8gkorepucocvtbrrxqq7tbszp9wzbuoii/xcv7dvsq8flb7c9346fcqb++tg95nlp7sattpj8xx29+7xfxhbfry/tgodt/6kbpgserornaz7vfxwsy2n7gtudnipoacq69q+pjkxsdwm6qlczkfh1wggbdbyfrfnprbrz5em7nlhr2lwi/wyt2zxw9lo7s4sopu+fcoakvo9mogbm83rcpiygpg68kj3m6ipriq18/civyvzvliqhbc7cuaisxaygdd9cz2a/1zz1k3s/bo5fgvsuf+nn4t+kgwlqayn9as86ylfto5a+umbyiqdgv3jmslht8un+kksdxkufyhsegojvyzomz2bpe7ryqfwdfsn81rw06rggdvagvrykbez/axbinqt9/tuwvrnw2ynm8fnzswjzxvfyastb7yq/5fvmfasqjwm6/ih67ip6/al860uwcdzslvkbtmx48y3okd+dhvsixk09gsljdi28thdn+wl5lwmgunp7hevlz+qt7w3nnfay67ihiivc1qacp/0/5rfhci5evyy0jlxiglhvkn3ya7rqnkwxxdskt55z8tbwwumyfcexll71ssmd5bhy9lihde4rzdfimwwidwvcd/e3ancgjwx69z/tpcasplkqp4wo9xwmbyz6ejuzs7h/qtnfhmvpspfzzj47lpjitr/2zpiqwal4xqsrehvyudp7iomxmt2dofzfsd9itvcfpv2l35zewr0qjmoes6q4irqcwxeadb0/tipfnmx7rqigzxri1zdx7frsxfj7ol96hlcjmxkjipxu11t/jqxdzsrch7jjj+y8fvvhe25evli745ddt0s/ernxo4tvuz0ckrzyv/5ci/kx3vx6wkgsf8k8cxxu7/6w/5elayzfl+ohb+5v0ne/11twrd+hlw1vfj7i478/d+nwcbwwn9wzkttzys2ewmzqwood+mp70cx5snvu/qswzxnxv/aohnjmzcsb/xrm3ganacv47wcsf3nisjjdqnql7zddd459nxw3bjz1if2vanzq3itkdxsxka/eao1d8n6x/ll1wfmrmm+po4gzfg39zrolgpqykpho9ohuqmqbqdas28x36sfzlpqauii3bzebxjxwnvejjwehqyngkzqheys0lujt/4lhd0qy8lvzs4xpccy/bewn5fk7x5wfye84wk5dnycvdtsnzheedkwatskxxsfhg5lzzifmwx/aqa6rjelsqbpmw8fah30wok+jyewph9hcjynglwwzyqdqpwaynbzehruewtpnkz0evzipg/2ikhfkzfiouyrnjlddjkkfhb+yazjvn9q8zoxga7ikpfavfx8q12jdgglvd3mwcgy2jcrdlvmxsw/eizdx0xxfb+iqykiojpiuq89gdaluphwdenccsdjm0zdd1ks3l8bscoanvbeo7ezuurstqrxzew9sbb8evxi29j47h0cmhenf0+b+pt54c3mnckr/ohdsytbhlwkqylxbioyy4rcxwz9fpeum/ha/ue7fpxpny9q/poqo+utjvfbzv+cvywy+haepwcexjint77vvcxbryxd6wwefjcsvw1pwwxfbx8bncyo/kvvvokdqpkyxhydyg/eexd4jrt10mme3bbo4cxy+07peskowyrphmis9feilpzn1epn63ldrffcthserfqdddqub2txf/wkaccvlhchszvwxj4agtfj4od73mjtaeyiey2imsfubtq5u94n0zrnia7gcpo5s0xkxsrdy3buprbdvgdp9kml5zj/fpnuo9mqpl7e3ur94m5vv/gexwjo/izgqpww/+ms8oqml2mfcuic6fk+hgxmwrpwkuwakovevrctswpk4g00h/885af4ibet9th8jz9nohobpdssnwuetc/w6c1d/pltu4i8g8n2ph0v9d2+kp6u1pznslrfdsah6ca8iyjhyuguuhga3h1byktsoca8krjftsfaxvcbmt3lty2qignnk5lvwtfef24k6pnyvs9x4ry7srac2o/yndwophquvil36nou/6utuypq+qtrir2zejbos+oexdopwvazjcwtfo2ndh2awhzxk9woxbhig03hkgsuk22aqd2xfojuzbbrjmvpy9mp5bxij9f0pelczb7mizd14rzgzv21n57mfy5oquvvo09pipgedku2hgcwvzcpb3pi7laju6d6bbx3hzkhm/liuxvh/90tovlzrrggzue8tbwmiqc9yfmxgabtf49ul/lkzmpkq49ceokuavrmolxt75xiele8sjbzafa9vianezwcd+y0zej6gz3w+o0+om342qrmrdzd6o5dio/gnmgadr9rjmpvkxrwwlgrzdjip5kwpjt2buznsplzhicgevvcndgal48tlytahklqqwbtp/b5ggxys6ik+zx3n1yyzybpfxj5vdzpailmt0so5fhili4o6j1bqgvfnc6cw8bjc0e0zsbfbi4dphlfecnsxfy7z1fkih1yyrnsotvygxkti1uc/xvzrsz8ejebe8oba/bxqb393tbpf3hln97slwa2ueklxhccosr9az8ahyzf61eprxaq59+vxbl1a6dtbx6fvtp+stjxiy1zpxtfus5u/1ea3+f5e6s91c4xplsvqs4pa7kvspma76fdku5fp78a5zx7v9ri6yqz6bpw9vez/m4r49vi75goay8fewwih8r6m8gkglgb1qecniujgj3ftgxbsaqiggoj7eu+wgsomvhqxpu1trayidr9bbxkkho/06smo+r7+w5arkdad+t+vpxfxlxrowgdix9ek/+bl957bhsyw+h/0bsodzt9hhn5c4uqpo1vg4i+bp1u5ssa24egfkehkabbgke8/zo0sh2jhgmnsom1do5aztnsc4rsxanwt+biyas8/wipgtoscij09jt1gy+jdynh/kw1cnl+iycimbjf6t9rru8y8b6vnl9bcgdco2/1n70xdylnacuhhpgcch5+pcqezemv2yb/fhrxsbwfl9bepzqukhipbcwr8c6dndcp5cyxbpjjrqcnuhnszzilblz6viqo9yy7pxdtoq9b1hq9ugnrskm/dbg3nkprl7bil6hqrq7+ezf5kzjkauyza17wrkbpe39yxipo7nh7mkks4+bgdhpuymjn/ke0wuqrxahs2h62bcygsxyvdjaroxko5ycvwcyl7jx8kgpbzjerhi3+xvuzgm+8au29xny69lrb5/mkrgvfayitfbda+kcxfijkmxdhkqmrpqcgx8ecfzikzgjydgrkxb+eeexqnbbqn/y25636youfqp35zqbgjmay9sf9/iulcdwx7zatllk3lwug56rjnqsrbxstnek+wn3udu5n0hgolaz4dchqktvgipg3xb/ztmw7cxmeyikmfwgh340oxr4a6bpu4lx7ly45e5e4nyqscgyjq/i2omo1ljsb35ief3h83bwxwpsq231fk2g89b8whrwfq/aeyju8oecun+xhr0bjuvsi6zbmnhqbzimndaavbn4ji7vyttbzibpgoyubz3gergbulnw5zidog/fpk8hntgpa1bwqmvsqdjt12zocn+r9uo7pboz6hyiwvyxlfhi/u00pffuzahtlfhthdc3fkabj2rmtaktufmvb+jbgvcx90uyfenhypuuodrfpddnjuhyf4pbbcmynicy2bkygaayvvp+fbx/dzfgbg5gedghtp3frj93+jvdw4utr1algcde0guad72c+eaaab4ngngzgdgkp/7guezh8p/o/8polgygcioiauarbyhdhic42aaghqgbpanxgeobghm1uswktgbbbabanvka/ftij6gks8qb6gzfkf8gqjn8hai+bcbyfqbqc4kid9d9yga7wif6pshpfwandpebjzoic3gwmc8bagmenmsvlagggeowxubfesgzgskfuo4h+kyecv/n2j5bzqh6cywyyd9hrvbwbcc5bsbatkaeqigyuwxoeyd3cj6eyh3byhzglgl4m/2ekrygowa+8mgqgmalgwgwgaaaaaadaa0aeoacgcmamoa9aewauqbighgadqchajiapwc2amsa3ad1ap6bbieigrgbfoe4gvybxafngx0bgaggaawbuwhcgc0b6yieggmcfaihaiocnijaglmcygjvaocclqkjaqycuwlcas0c2qlmau+c/gmmgxedjimqazodqwnpg1cdxqnta3kdgyola5kdmyoha6cdrgo4g8ydzwpog/ed94p9haoefqqhhdqeryrmhfseyyrshhmefwsdbkmesqtrhnue+oaahicy2bkygbiyqhm4giaasyg5gkz/4p5daab1whyaaaaejxlkbtuwkaurmc88gapqomujoq0tdiqzeopudokkcnr0buzbio/tf6qsjcpyhfle9klyyekz2cug8cr7547m3d9jqo4xjccnj57vid2cmhqxdwc40g4tv1juef+fm6ijrfhm+oz4ra6ebvu4wzvvmfpxlia40pyqqefwjvc4uu4tv1hueh+fw7i1mkkn6hj3am3shc6wm08ou8tpszge1av1pkggjsxpd8zjtsgtuinyvga6/uu8kxzludcmzxmezv0b6u004k25w35fj2ynlcbswm1paujkfwzsbfat+7g2mzc7weiu34aczzfnygbhgflfcv6iqp3acksaj349axxsn9it0j16jepob01doikbnwt1ovippz6svyywsxgx2rgvfikq7pl2pnri6qw6eoshj0xasq9mpneziws8lzufoounkvxxp/d5woqebeyif4d2j1ywqb4ng2rr3fuqbce9rmmytmbndmkeysytjliowfwu/z7xljxhj8fvk0jottmvhdxt6qthcs+5et/35wf1rgertawxey2szktbgub29nbtnaxmz3szr/7ocbbdngyzy5wlgmc5wqnocvpzncwc5znahe5xgwucjvrxccli6fa4qlesipucjnb3oyod7lhtcoelo6e+zzgiy94zboe8oznvoalr3jng97yjvd84cof+mwxvvkn7/xgygoz5qwm/fn8/etnkqozys4she7ohueyhawwwvqhrkvt4frdktaxyvusfhvazjjlps50tnkuphb1ko3uwanszvsvwbxtdmpqitcv33aajsjqxvbdma2vwhf98irjnfhklhflm6hpldntbpjyymdlelvekdtmkgmukpk7vq8v4zpuei+/vpk8fam6b7srn6xjuxym42t96jeccde1x7rchjh/ltgfounw1umrrz34qbnsj+qisfaktiwqiokj+dgdtzvurvl36lpe3o32fxwhf53+zunlyxm31vvsc3m5wjr1h51qnpehquywbrljfx2wlske/cbvzjrjne7cjclfjo7tgg== 17 ''' 18 19 def __init__(self, b64str): 20 self._sample_font_ = ttlib.ttfont( 21 bytesio(base64.b64decode(self._sample_font_str_)) 22 ) 23 self._font_ = ttlib.ttfont( 24 bytesio(base64.b64decode(b64str)) 25 ) 26 27 def parse_code(self, code): 28 code_uni = self._font_.getbestcmap().get(code, none) 29 if code_uni is none: 30 return chr(code) 31 code_obj = self._font_['glyf'][code_uni] 32 for uni in self._sample_font_.getglyphnames()[1:-1]: 33 if code_obj == self._sample_font_['glyf'][uni]: 34 return self._glyph_map_.get(uni, '') 35 return chr(code) 36 37 def parse_str(self, s): 38 res = '' 39 for c in s: 40 res += self.parse_code(ord(c)) 41 return res 42 43
上一篇: 深入浅析Mysql联合索引最左匹配原则