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´¦ÀíһЩÊý¾Ý£¬Êý¾ÝÐèÒª´æ´¢µ½MySQLÊý¾Ý¿âÖУ¬²ÉÓÃMySQLdbÀ´½øÐÐÊý¾Ý¿âµÄ²Ù×÷£¬µ«ÊDZ»Ò»¸öÎÊÌâÀ§ÈÅÁ˺ܾá£ÔÚ´ò¿ªÊý¾Ý¿âµÄʱºòMySQLdb.connect(self.host, self.user, self.password, self.database, port=self.port)³öÒì³££¬¶øÇÒÒì³£³öÏÖµÄλÖ÷dz£Ææ¹Ö¡£
³öÏÖÔÚconverters.py 164ÐÐ
from decimal import ......
̸µ½ÁËPythonÓï¾äµÄÁ½ÖÖÖ´Ðз½Ê½£¬Êµ¼ÊÉÏ£¬ÕâÁ½ÖÖÔËÐз½Ê½ÔÚ±¾ÖÊ ÉÏÊÇÏàͬµÄ£¬ËüÃǶ¼ÊÇÓɽâÊÍÆ÷À´½âÊÍÖ´ÐÐÎÒÃÇÌṩµÄPythonÓï¾ä¡£ ÕâÀïËù˵µÄ½âÊÍÖ´ÐÐÊÇÏà¶ÔÓÚ±àÒëÖ´ÐжøÑԵġ£ÎÒÃÇÖªµÀ£¬Ê¹ÓÃÖîÈç C»òC++Ö®ÀàµÄ±àÒëÐÔÓïÑÔ±àдµÄ³ÌÐò¿ÉÒÔ´ÓÔ´Îļþת»»³É¼ÆËã»úʹÓà µÄ»úÆ÷ÓïÑÔ£¬ ¾Á¬½ÓÆ÷Á¬½ÓºóÐγɶþ½øÖÆ¿ÉÖ´ÐÐÎļþ¡£µ±ÎÒÃÇÔ ......
ÏȽ«ÉÏÃæ´´½¨ºÃµÄtestdemo¹¤³ÌĿ¼\£¬½«C:\Python25\Lib\site-packages\django\binÖеÄtestdemoĿ¼¿½±´µ½×Ô¼ºµÄ¹¤×÷Ŀ¼ÖУ¬È»ºóÆô¶¯eclipse£¬µã»÷“File”->“New”->“project…”£¬½«»á¿´µ½ÒÔÏ»Ãæ
Ñ¡Ôñ“Pydev Project”£¬µã»÷“Next&rdquo ......
ʹÓà Python ·ÖÀëÖÐÎÄÓëÓ¢ÎĵĻìºÏ×Ö´®
LiYanrui
posted @ ´óÔ¼ 1 ÄêÇ°
in ³ÌÐòÉè¼Æ
with tags
python
, 614 ÔĶÁ
Õâ¸öÎÊÌâÊÇ×ö MkIV Ô¤´¦Àí³ÌÐò
ʱ¸ã¶¨µÄ£¬¾ÍÊÇ°ÑÒ»¸ö»ìºÏÁËÖÐÓ¢ÎÄ»ìºÏ×Ö´®·ÖÀëΪӢÎÄÓëÖÐÎĵÄ×Ó×Ö´®£¬Æ©È磬½« ”ÎÒµÄ English ѧµÄ²»ºÃ
&ld ......