易截截图软件、单文件、免安装、纯绿色、仅160KB

Python之HTMLParser

"""A parser for HTML and XHTML."""
# This file is based on sgmllib.py, but the API is slightly different.
# XXX There should be a way to distinguish between PCDATA (parsed
# character data -- the normal case), RCDATA (replaceable character
# data -- only char and entity references and end tags are special)
# and CDATA (character data -- only end tags are special).
import _markupbase
import re
# Regular expressions used for parsing
interesting_normal = re.compile('[&<]')
interesting_cdata = re.compile(r'<(/|\Z)')
incomplete = re.compile('&[a-zA-Z#]')
entityref = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]')
charref = re.compile('&#(?:[0-9]+|[xX][0-9a-fA-F]+)[^0-9a-fA-F]')
starttagopen = re.compile('<[a-zA-Z]')
piclose = re.compile('>')
commentclose = re.compile(r'--\s*>')
tagfind = re.compile('[a-zA-Z][-.a-zA-Z0-9:_]*')
attrfind = re.compile(
r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~@]*))?')
locatestarttagend = re.compile(r"""
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
(?:\s+ # whitespace before attribute name
(?:[a-zA-Z_][-.:a-zA-Z0-9_]* # attribute name
(?:\s*=\s* # value indicator
(?:'[^']*' # LITA-enclosed value
|\"[^\"]*\" # LIT-enclosed value
|[^'\">\s]+ # bare value
)
)?
)
)*
\s* # trailing whitespace
""", re.VERBOSE)
endendtag = re.compile('>')
endtagfind = re.compile('</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
class HTMLParseError(Exception):
"""Exception raised for all parse errors."""
def __init__(self, msg, position=(None, None)):
assert msg
self.msg = msg
self.lineno = position[0]
self.offset = position[1]
def __str__(self):
result = self.msg


相关文档:

使用C语言扩展Python(三)

上一篇中我们已经了解如何在Python程序和C模块之间进行值的相互传递,现在我们来进入实作阶段,看看如何将一个C语言开发的开源mp3编解码库LAME包装为一个Python下可以使用的扩展模块。首先去http://lame.sourceforge.net/download.php下载LAME的源代码,然后切换到root用户编译源代码,./configure
make
make instal ......

python发邮件的代码

# -*- coding: cp936 -*-
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib
 
#创建一个带附件的实例
msg = MIMEMultipart()
#构造附件
att = MIMEText(open('e:\\test.txt').read(), 'base64', 'gb2312')
att["Content-Type"] = 'application/ ......

python 命令行参数


本篇将介绍python中sys, getopt模块处理命令行参数
如果想对python脚本传参数,python中对应的argc, argv(c语言的命令行参数)是什么呢?
需要模块:sys
参数个数:len(sys.argv)
脚本名:    sys.argv[0]
参数1:     sys.argv[1]
参数2:     sys.argv[2]
test.py
1
import ......

Eclipse基于python、Django做Web开发

 先将上面创建好的testdemo工程目录\,将C:\Python25\Lib\site-packages\django\bin中的testdemo目录拷贝到自己的工作目录中,然后启动eclipse,点击“File”->“New”->“project…”,将会看到以下画面
 
选择“Pydev Project”,点击“Next&rdquo ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号