本文整理汇总了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 = []