本文整理匯總了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