将字符实体引用转换成 Unicode 字符

首先我们一起来看下 Character entities references (HTML Entities)和 Numeric Character Reference (NCR)的异同: HTML Entities 的格式如:&lt;,NCR 的格式如:&#60; 或 &#x3c;,均都表示“<” 字符。 HTML 中规定了 Character entity references,在 “24.2.1 The list of characters” 列出了 HTML Entities 和 NCR 的对应关系,例如: <!ENTITY nbsp CDATA “&#160;” — no-break space = non-breaking space, U+00A0 ISOnum –> <!ENTITY iexcl CDATA “&#161;” — inverted exclamation mark, U+00A1 […]

... 5 条评论 »

用python将文本转成图片

#-*- coding:utf-8 -*- import Image, ImageDraw, ImageFont, uuid def text2png(text): # config: adTexts = [‘—————‘, ‘http://www.planabc.net’] imgBg = ‘#FFFFFF’ textColor = “#000000” adColor = “#FF0000” ttf = “C:\Windows\Fonts\STXIHEI.TTF” fontSize = 20 tmp = ‘tmp/’ # Build rich text for ads ads = [] for adText in adTexts: ads += [(adText.decode(‘utf-8’), adColor)] # Format wrapped lines […]

... 5 条评论 »

用 Python 架设一个简单的服务器

import string,cgi,time from os import curdir, sep from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer class MyRequestHandler(BaseHTTPRequestHandler): def do_GET(self): try: if self.path.endswith(‘.html’): f = open(curdir + sep + self.path) self.send_response(200) self.send_header(‘Content-type’,’text/html’) self.end_headers() self.wfile.write(f.read()) f.close() return elif self.path.endswith(‘.py’): self.send_response(200) self.send_header(‘Content-type’,’text/html’) self.end_headers() self.wfile.write(“hey, today is the” + str(time.localtime()[7])) self.wfile.write(” day in the year ” + str(time.localtime()[0])) return else: self.send_error(404, ‘File […]

... 6 条评论 »