本文整理匯總了Python中sgmllib.SGMLParser方法的典型用法代碼示例。如果您正苦於以下問題:Python sgmllib.SGMLParser方法的具體用法?Python sgmllib.SGMLParser怎麽用?Python sgmllib.SGMLParser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sgmllib
的用法示例。
在下文中一共展示了sgmllib.SGMLParser方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse_declaration
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def parse_declaration(self, i):
"""Treat a bogus SGML declaration as raw data. Treat a CDATA
declaration as a CData object."""
j = None
if self.rawdata[i:i+9] == '<![CDATA[':
k = self.rawdata.find(']]>', i)
if k == -1:
k = len(self.rawdata)
data = self.rawdata[i+9:k]
j = k+3
self._toStringSubclass(data, CData)
else:
try:
j = sgmllib.SGMLParser.parse_declaration(self, i)
except sgmllib.SGMLParseError:
toHandle = self.rawdata[i:]
self.handle_data(toHandle)
j = i + len(toHandle)
return j
示例2: __init__
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def __init__(self):
sgmllib.SGMLParser.__init__(self)
示例3: __init__
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def __init__(self, formatter, verbose=0):
"""Creates an instance of the HTMLParser class.
The formatter parameter is the formatter instance associated with
the parser.
"""
sgmllib.SGMLParser.__init__(self, verbose)
self.formatter = formatter
示例4: reset
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def reset(self):
sgmllib.SGMLParser.reset(self)
self.savedata = None
self.isindex = 0
self.title = None
self.base = None
self.anchor = None
self.anchorlist = []
self.nofill = 0
self.list_stack = []
# ------ Methods used internally; some may be overridden
# --- Formatter interface, taking care of 'savedata' mode;
# shouldn't need to be overridden
示例5: __init__
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def __init__(self):
sgmllib.SGMLParser.__init__(self)
示例6: __init__
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def __init__(self, encoding, _type):
self.encoding = encoding
self._type = _type
sgmllib.SGMLParser.__init__(self)
示例7: reset
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def reset(self):
self.pieces = []
sgmllib.SGMLParser.reset(self)
示例8: feed
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def feed(self, data):
data = re.compile(r'<!((?!DOCTYPE|--|\[))', re.IGNORECASE).sub(r'<!\1', data)
data = re.sub(r'<([^<>\s]+?)\s*/>', self._shorttag_replace, data)
data = data.replace(''', "'")
data = data.replace('"', '"')
try:
bytes
if bytes is str:
raise NameError
self.encoding = self.encoding + u'_INVALID_PYTHON_3'
except NameError:
if self.encoding and isinstance(data, unicode):
data = data.encode(self.encoding)
sgmllib.SGMLParser.feed(self, data)
sgmllib.SGMLParser.close(self)
示例9: parse_declaration
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def parse_declaration(self, i):
try:
return sgmllib.SGMLParser.parse_declaration(self, i)
except sgmllib.SGMLParseError:
# escape the doctype declaration and continue parsing
self.handle_data('<')
return i+1
示例10: __init__
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def __init__(self, url, verbose=VERBOSE, checker=None):
self.myverbose = verbose # now unused
self.checker = checker
self.base = None
self.links = {}
self.names = []
self.url = url
sgmllib.SGMLParser.__init__(self)
示例11: __init__
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def __init__(self, entitydefs=None, encoding=DEFAULT_ENCODING):
sgmllib.SGMLParser.__init__(self)
_AbstractFormParser.__init__(self, entitydefs, encoding)
示例12: feed
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def feed(self, data):
try:
sgmllib.SGMLParser.feed(self, data)
except SGMLLIB_PARSEERROR, exc:
raise ParseError(exc)
示例13: close
# 需要導入模塊: import sgmllib [as 別名]
# 或者: from sgmllib import SGMLParser [as 別名]
def close(self):
sgmllib.SGMLParser.close(self)
self.end_body()
# sigh, must support mechanize by allowing dynamic creation of classes based on
# its bundled copy of BeautifulSoup (which was necessary because of dependency
# problems)