@@ -21,7 +21,9 @@ def get_form_details(form):
2121 including action, method and list of form controls (inputs, etc)"""
2222details = {}
2323# get the form action (requested URL)
24- action = form .attrs .get ("action" ).lower ()
24+ action = form .attrs .get ("action" )
25+ if action :
26+ action = action .lower ()
2527# get the form method (POST, GET, DELETE, etc)
2628# if not specified, GET is the default in HTML
2729method = form .attrs .get ("method" ,"get" ).lower ()
@@ -36,6 +38,38 @@ def get_form_details(form):
3638input_value = input_tag .attrs .get ("value" ,"" )
3739# add everything to that list
3840inputs .append ({"type" :input_type ,"name" :input_name ,"value" :input_value })
41+ for select in form .find_all ("select" ):
42+ # get the name attribute
43+ select_name = select .attrs .get ("name" )
44+ # set the type as select
45+ select_type = "select"
46+ select_options = []
47+ # the default select value
48+ select_default_value = ""
49+ # iterate over options and get the value of each
50+ for select_option in select .find_all ("option" ):
51+ # get the option value used to submit the form
52+ option_value = select_option .attrs .get ("value" )
53+ if option_value :
54+ select_options .append (option_value )
55+ if select_option .attrs .get ("selected" ):
56+ # if 'selected' attribute is set, set this option as default
57+ select_default_value = option_value
58+ if not select_default_value and select_options :
59+ # if the default is not set, and there are options, take the first option as default
60+ select_default_value = select_options [0 ]
61+ # add the select to the inputs list
62+ inputs .append ({"type" :select_type ,"name" :select_name ,"values" :select_options ,"value" :select_default_value })
63+ for textarea in form .find_all ("textarea" ):
64+ # get the name attribute
65+ textarea_name = textarea .attrs .get ("name" )
66+ # set the type as textarea
67+ textarea_type = "textarea"
68+ # get the textarea value
69+ textarea_value = textarea .attrs .get ("value" ,"" )
70+ # add the textarea to the inputs list
71+ inputs .append ({"type" :textarea_type ,"name" :textarea_name ,"value" :textarea_value })
72+
3973# put everything to the resulting dictionary
4074details ["action" ]= action
4175details ["method" ]= method