Merge dev.scrapinghub.com:~/src/scrapy

This commit is contained in:
Daniel Graña 2012-04-20 09:32:43 -03:00
commit 28401fd47d
1 changed files with 17 additions and 8 deletions

View File

@ -93,16 +93,25 @@ def _get_inputs(form, formdata, dont_click, clickdata, response):
def _value(ele):
n = ele.name
v = ele.value
# Match browser behaviour on simple select tag without options selected
# Or for select tags wihout options
if v is None and ele.tag == 'select' and not ele.multiple:
o = ele.value_options
if o:
return n, o[0]
else:
return None, None
if ele.tag == 'select':
return _select_value(ele, n, v)
return n, v
def _select_value(ele, n, v):
multiple = ele.multiple
if v is None and not multiple:
# Match browser behaviour on simple select tag without options selected
# And for select tags wihout options
o = ele.value_options
return (n, o[0]) if o else (None, None)
elif v is not None and multiple:
# This is a workround to bug in lxml fixed 2.3.1
# fix https://github.com/lxml/lxml/commit/57f49eed82068a20da3db8f1b18ae00c1bab8b12#L1L1139
selected_options = ele.xpath('.//option[@selected]')
v = [(o.get('value') or o.text or u'').strip() for o in selected_options]
return n, v
def _get_clickable(clickdata, form):
"""
Returns the clickable element specified in clickdata,