本文整理匯總了Python中html.parser.HTMLParser.reset方法的典型用法代碼示例。如果您正苦於以下問題:Python HTMLParser.reset方法的具體用法?Python HTMLParser.reset怎麽用?Python HTMLParser.reset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類html.parser.HTMLParser
的用法示例。
在下文中一共展示了HTMLParser.reset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: start_seq
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def start_seq(self, attr):
#if it has a template, use that; otherwise try for id;
#otherwise take default sequence
if 'template' in attr:
templ = attr['template']
self.handle_data(templ % self._seq)
return
elif 'id' in attr:
id = attr['id']
else:
id = None
increment = attr.get('inc', None)
if not increment:
output = self._seq.nextf(id)
else:
#accepts "no" for do not increment, or an integer.
#thus, 0 and 1 increment by the right amounts.
if increment.lower() == 'no':
output = self._seq.thisf(id)
else:
incr = int(increment)
output = self._seq.thisf(id)
self._seq.reset(id, self._seq._this() + incr)
self.handle_data(output)
示例2: reset
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def reset(self):
self.elements = []
self.processing = []
HTMLParser.reset(self)
示例3: reset
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def reset(self):
self.allData = []
self.allhref = []
HTMLParser.reset(self)
#
# Appends HTML file content to allData variable
#
示例4: reset
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def reset(self):
self.allData = []
HTMLParser.reset(self)
#
# Appends HTML file content to allData variable
#
示例5: __init__
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def __init__(self, filename=None, encoding='utf-8'):
'''
__init__ - Creates an Advanced HTML parser object. For read-only parsing, consider IndexedAdvancedHTMLParser for faster searching.
@param filename <str> - Optional filename to parse. Otherwise use parseFile or parseStr methods.
@param encoding <str> - Specifies the document encoding. Default utf-8
'''
HTMLParser.__init__(self)
# Do not automatically convert charrefs in python3
self.convert_charrefs = False
# Encoding to use for this document
self.encoding = encoding
self._inTag = []
self.root = None
self.doctype = None
self.reset = self._reset # Must assign after first call, otherwise members won't yet be present
if filename is not None:
self.parseFile(filename)
###########################################
##### INTERNAL #######
###########################################
示例6: __getstate__
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def __getstate__(self):
'''
__getstate__ - Get state for pickling
@return <dict>
'''
state = self.__dict__
# Python2 compat
del state['reset']
return state
示例7: __setstate__
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def __setstate__(self, state):
'''
__setstate - Restore state for loading pickle
@param state <dict> - The state
'''
for key, value in state.items():
setattr(self, key, value)
# Python2 compat
self.reset = self._reset
示例8: _reset
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def _reset(self):
'''
_reset - reset this object. Assigned to .reset after __init__ call.
'''
HTMLParser.reset(self)
self.root = None
self.doctype = None
self._inTag = []
示例9: feed
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def feed(self, contents):
'''
feed - Feed contents. Use parseStr or parseFile instead.
@param contents - Contents
'''
contents = stripIEConditionals(contents)
try:
HTMLParser.feed(self, contents)
except MultipleRootNodeException:
self.reset()
HTMLParser.feed(self, "%s%s" %(addStartTag(contents, INVISIBLE_ROOT_TAG_START), INVISIBLE_ROOT_TAG_END))
示例10: parseStr
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def parseStr(self, html):
'''
parseStr - Parses a string and creates the DOM tree and indexes.
@param html <str> - valid HTML
'''
self.reset()
if isinstance(html, bytes):
self.feed(html.decode(self.encoding))
else:
self.feed(html)
示例11: __init__
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def __init__(self, indent=' ', encoding='utf-8'):
'''
Create a pretty formatter.
@param indent <str/int>, Default ' ' [4 spaces] - Either a space/tab/newline that represents one level of indent, or an integer to use that number of spaces
@param encoding <str/None>, Default 'utf-8', - Use this encoding for the document. None to not mess with encoding
'''
HTMLParser.__init__(self)
# Do not automatically convert charrefs in python3
self.convert_charrefs = False
self.parsedData = []
self.reset = self._reset
self.decl = None
self.currentIndentLevel = 0
self.indent = indent
self.encoding = encoding
self.inPreformatted = 0
self.root = None
self._inTag = []
self.doctype = None
示例12: feed
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def feed(self, contents):
'''
feed - Load contents
@param contents - HTML contents
'''
contents = stripIEConditionals(contents)
try:
HTMLParser.feed(self, contents)
except MultipleRootNodeException:
self.reset()
HTMLParser.feed(self, "%s%s" %(addStartTag(contents, INVISIBLE_ROOT_TAG_START), INVISIBLE_ROOT_TAG_END))
示例13: _reset
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def _reset(self):
HTMLParser.reset(self)
self.currentIndentLevel = 0
self.parsedData = []
self._inTag = []
self.root = None
self.doctype = None
self.inPreformatted = 0
示例14: parseStr
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def parseStr(self, html):
'''
parseStr - Parses a string and creates the DOM tree and indexes.
@param html <str> - valid HTML
'''
self.reset()
if isinstance(html, bytes):
self.feed(html.decode(self.encoding))
else:
self.feed(html)
示例15: reset
# 需要導入模塊: from html.parser import HTMLParser [as 別名]
# 或者: from html.parser.HTMLParser import reset [as 別名]
def reset(self):
HTMLParser.reset(self)
self.data = []
self.p = []