本文整理汇总了Python中six.moves.html_parser.HTMLParser类的典型用法代码示例。如果您正苦于以下问题:Python HTMLParser类的具体用法?Python HTMLParser怎么用?Python HTMLParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTMLParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: feed
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('"', '"')
HTMLParser.feed(self, data)
HTMLParser.close(self)
示例2: __init__
def __init__(self):
HTMLParser.__init__(self)
self.links = []
self.in_anchor = False
self.attrs = None
self.title = ''
示例3: __init__
def __init__(self, *args, **kwargs):
if sys.version_info > (3,4): #pragma: no cover
HTMLParser.__init__(self, convert_charrefs=False)
else: #pragma: no cover
HTMLParser.__init__(self)
super(HTMLRewriter, self).__init__(*args, **kwargs)
示例4: feed
def feed(self, string):
try:
HTMLParser.feed(self, string)
except Exception as e: # pragma: no cover
import traceback
traceback.print_exc()
self.out.write(string)
示例5: display_link_prompt
def display_link_prompt(args, urls, titles):
"""Print URLs and their descriptions alongside a prompt.
Keyword arguments:
args -- program arguments (dict)
urls -- search URLs found (list)
titles -- descriptions of search URLs found (list)
"""
while 1:
print('\n{0}'.format(BORDER))
for i in range(len(urls)):
link = HTMLParser().unescape(titles[i])
print('{0}. {1}'.format(i+1, link.encode('utf-8') if PY2 else link))
print(BORDER)
# Handle link prompt input
try:
link_input = [inp.strip() for inp in input(': ').split()]
if not link_input:
continue
utils.check_input(link_input) # Check input in case of quit
print('\n')
exec_prompt_cmd(args, urls, link_input[0], link_input[1:])
except (KeyboardInterrupt, EOFError, ValueError, IndexError):
return False
示例6: original_unescape
def original_unescape(self, s):
"""Since we need to use this sometimes"""
if isinstance(s, basestring):
return unicode(HTMLParser.unescape(self, s))
elif isinstance(s, list):
return [unicode(HTMLParser.unescape(self, item)) for item in s]
else:
return s
示例7: __init__
def __init__(self, style, styles = None):
HTMLParser.__init__(self)
self.s = ''
self.style = style
self.styles = styles if styles else default_styles
self.style_stack = []
示例8: __init__
def __init__(self, media_locator, link_handler):
HTMLParser.__init__(self)
self.handlers_start = StartRules(media_locator, link_handler)
self.handlers_startend = StartEndRules(media_locator, link_handler)
self.handlers_end = EndRules()
self.new_buffer()
self.stack = deque()
self.stack.append([])
示例9: __init__
def __init__(self, max_words):
# In Python 2, HTMLParser is not a new-style class,
# hence super() cannot be used.
HTMLParser.__init__(self)
self.max_words = max_words
self.words_found = 0
self.open_tags = []
self.truncate_at = None
示例10: feed
def feed(self, *args, **kwargs):
try:
# With Python 2, super() cannot be used.
# See the comment for __init__().
HTMLParser.feed(self, *args, **kwargs)
except self.TruncationCompleted as exc:
self.truncate_at = exc.truncate_at
else:
self.truncate_at = None
示例11: __init__
def __init__(self):
HTMLParser.__init__(self)
self._ignore = False
self._ignorePath = None
self._lasttag = None
self._depth = 0
self.depthText = {} # path:text
self.counting = 0
self.lastN = 0
示例12: __init__
def __init__(self):
HTMLParser.__init__(self)
self.text_name = None
self.original_value = None
self.new_value = None
self.in_tag = False
self.read_buffer = six.StringIO()
示例13: cmd_genpot
def cmd_genpot(config, options):
"""Generate the gettext pot file"""
os.chdir(config.source_dir)
po_path = os.path.join(config.source_dir, 'po')
if not os.path.isdir(po_path):
os.mkdir(po_path)
python_files = []
for root, dirs_dummy, files in os.walk(config.source_dir):
for file_name in files:
if file_name.endswith('.py'):
file_path = os.path.relpath(os.path.join(root, file_name),
config.source_dir)
python_files.append(file_path)
python_files.sort()
# First write out a stub .pot file containing just the translated
# activity name, then have xgettext merge the rest of the
# translations into that. (We can't just append the activity name
# to the end of the .pot file afterwards, because that might
# create a duplicate msgid.)
pot_file = os.path.join('po', '%s.pot' % config.bundle_name)
escaped_name = _po_escape(config.activity_name)
f = open(pot_file, 'w')
f.write('#: activity/activity.info:2\n')
f.write('msgid "%s"\n' % escaped_name)
f.write('msgstr ""\n')
if config.summary is not None:
escaped_summary = _po_escape(config.summary)
f.write('#: activity/activity.info:3\n')
f.write('msgid "%s"\n' % escaped_summary)
f.write('msgstr ""\n')
if config.description is not None:
parser = HTMLParser()
strings = []
parser.handle_data = strings.append
parser.feed(config.description)
for s in strings:
s = s.strip()
if s:
f.write('#: activity/activity.info:4\n')
f.write('msgid "%s"\n' % _po_escape(s))
f.write('msgstr ""\n')
f.close()
args = ['xgettext', '--join-existing', '--language=Python',
'--keyword=_', '--add-comments=TRANS:', '--output=%s' % pot_file]
args += python_files
retcode = subprocess.call(args)
if retcode:
print('ERROR - xgettext failed with return code %i.' % retcode)
示例14: logged_in
def logged_in(self, y):
if all([None is y or 'logout' in y,
bool(filter(lambda c: 'remember_web_' in c, self.session.cookies.keys()))]):
if None is not y:
self.shows = dict(re.findall('<option value="(\d+)">(.*?)</option>', y))
h = HTMLParser()
for k, v in self.shows.items():
self.shows[k] = sanitizeSceneName(h.unescape(unidecode(v.decode('utf-8'))))
return True
return False
示例15: add_set
def add_set(self, title, description, index=-1):
widget = QtWidgets.QCheckBox(title.replace('&', '&&'))
if description:
h = HTMLParser()
widget.setToolTip(h.unescape(description))
if index >= 0:
self.sets_widget.layout().insertWidget(index, widget)
else:
self.sets_widget.layout().addWidget(widget)
return widget