本文整理汇总了Python中lxml.html._nons方法的典型用法代码示例。如果您正苦于以下问题:Python html._nons方法的具体用法?Python html._nons怎么用?Python html._nons使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.html
的用法示例。
在下文中一共展示了html._nons方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _takes_multiple
# 需要导入模块: from lxml import html [as 别名]
# 或者: from lxml.html import _nons [as 别名]
def _takes_multiple(input):
if _nons(input.tag) == 'select' and input.get('multiple'):
# FIXME: multiple="0"?
return True
type = input.get('type', '').lower()
if type in ('radio', 'checkbox'):
return True
return False
示例2: _fill_multiple
# 需要导入模块: from lxml import html [as 别名]
# 或者: from lxml.html import _nons [as 别名]
def _fill_multiple(input, value):
type = input.get('type', '').lower()
if type == 'checkbox':
v = input.get('value')
if v is None:
if not value:
result = False
else:
result = value[0]
if isinstance(value, basestring):
# The only valid "on" value for an unnamed checkbox is 'on'
result = result == 'on'
_check(input, result)
else:
_check(input, v in value)
elif type == 'radio':
v = input.get('value')
_check(input, v in value)
else:
assert _nons(input.tag) == 'select'
for option in _options_xpath(input):
v = option.get('value')
if v is None:
# This seems to be the default, at least on IE
# FIXME: but I'm not sure
v = option.text_content()
_select(option, v in value)
示例3: _fill_single
# 需要导入模块: from lxml import html [as 别名]
# 或者: from lxml.html import _nons [as 别名]
def _fill_single(input, value):
if _nons(input.tag) == 'textarea':
input.text = value
else:
input.set('value', value)
示例4: _insert_error
# 需要导入模块: from lxml import html [as 别名]
# 或者: from lxml.html import _nons [as 别名]
def _insert_error(el, error, error_class, error_creator):
if _nons(el.tag) in defs.empty_tags or _nons(el.tag) == 'textarea':
is_block = False
else:
is_block = True
if _nons(el.tag) != 'form' and error_class:
_add_class(el, error_class)
if el.get('id'):
labels = _label_for_xpath(el, for_id=el.get('id'))
if labels:
for label in labels:
_add_class(label, error_class)
error_creator(el, is_block, error)
示例5: form_values
# 需要导入模块: from lxml import html [as 别名]
# 或者: from lxml.html import _nons [as 别名]
def form_values(self):
"""
Return a list of tuples of the field values for the form.
This is suitable to be passed to ``urllib.urlencode()``.
"""
results = []
for el in self.inputs:
name = el.name
if not name:
continue
tag = _nons(el.tag)
if tag == 'textarea':
results.append((name, el.value))
elif tag == 'select':
value = el.value
if el.multiple:
for v in value:
results.append((name, v))
elif value is not None:
results.append((name, el.value))
else:
assert tag == 'input', (
"Unexpected tag: %r" % el)
if el.checkable and not el.checked:
continue
if el.type in ('image', 'reset'):
continue
value = el.value
if value is not None:
results.append((name, el.value))
return results