Skip to content

Instantly share code, notes, and snippets.

@sash13
Created June 29, 2012 17:15
Show Gist options
  • Select an option

  • Save sash13/3019324 to your computer and use it in GitHub Desktop.

Select an option

Save sash13/3019324 to your computer and use it in GitHub Desktop.
def input_parse(base):
query = 'input '
input_parts = {}
sta=0
while sta !=-1:
sta=base[1:].find(query)
if sta == -1:
break
sta_len = sta+len(query)
end = base[sta_len:].find('>')+sta_len
stroka = base[sta_len:end]
name = stroka.split('name="')[1].split('"')[0]
try:
value = stroka.split('value="')[1].split('"')[0]
except:
value = ''
input_parts[name]=value
base=base[end:]
return input_parts
def input_parse(base):
input_list = {}
htmltree = lxml.html.fromstring(base)
for input_q in htmltree.xpath('//input'):
try:
input_list[input_q.attrib['name']]=input_q.attrib['value']
except:
pass
return input_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment