易截截图软件、单文件、免安装、纯绿色、仅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


相关文档:

Python学习笔记

Python简单又功能强大。它注重的是如何解决问题,而不是编程语言的语法和结构。理想的脚本语言。适用于快速的应用程序开发。
Python是一种解释性语言。还是一种面向对象的语言。
有两种使用python运行你的程序的方式:
      使用交互式的带提示符的解释器
      使 ......

关于Python正则表达式的区分大小写的问题

最近在用Python处理一些数据,数据需要存储到MySQL数据库中,采用MySQLdb来进行数据库的操作,但是被一个问题困扰了很久。在打开数据库的时候MySQLdb.connect(self.host, self.user, self.password, self.database, port=self.port)出异常,而且异常出现的位置非常奇怪。
出现在converters.py 164行
from decimal import ......

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 ......

python时间转为时间戳

找了半天没找着,终于在英文站点上找到,还有感谢群里的石头和球迷
>>> s = datetime.datetime(2009,1,1)
>>> time.mktime(s.timetuple())
1230739200.0
别外付一个python对时间的一些函数,很好用的
我们先导入必须用到的一个module
>>> import time
设置一个时间的格式,下面会用到
& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号