python - How to submit a form with a get action using Robobrowser -


I am using a robobrowser library, I have come across a form:

  & Lt; Form action = "/ results" id = "search" & gt; & Lt; Div class = "s_ctr" & gt; & Lt; Fieldset & gt; & Lt; Label class = "jaw" = "ln" & gt; Search by name & lt; / Label & gt; & Lt; Input type = "text" placeholder = "search by name" autocomplete = "off" value = "" tabindex = "1" Name = "ln" maxlength = "255" class = "name" id = "ln" data-key = "True" & gt; & Lt; Span & gt; Near & lt; / Span & gt; & Lt; Label class = "jaw" = "input" = "text" placeholder = "enter city, state" autocomplete = "off" value = "" tabindex = "2" name = "public" maxlength = "255" square = "Location" id = "loc" data-key = "true" & gt; & Lt; / Fieldset & gt; & Lt; Input type = "submit" value = "find doctor" class = "orange-btn" tabindex = "4" id = "btn-deposit" & gt; & Lt; / Div & gt; & Lt; / Form & gt;  

My code:

  search_form = browser.get_form (id = 'search') search_form search_form.fields ['1'] = name search_form.fields <'<'>  

I get the following error and traceback:

  traceback: file "c: \ r1 \ lib \ site-packages \ django \ Core \ handlers \ base.py "get_response 114. response = wrapped_callback (request, * callback_args, ** callback_kwargs) file" c: \ r1 \ lib \ site -packages \ django \ views \ decorators \ csrf.py "wrapped_view 57 Return view_func (* args, ** kwargs) in the file "C: \ r1 \ mlist \ ml1 \ views.py" in pH 48 P = getPhone (A.name, A.address) file "C: \ r1 \ mlist \ ml1 \ views.py" in getPhone 191 Browser.submit_form (search_form) file "c: \ r1 \ lib \ site-packages \ robobrowser \ browser Py" submit_form 343 225 return payload.frame_field (included_field) file "C: \ r1 \ lib \" in serialize, "payload = form.serialize (submit = submit) file" c: \ r1 \ lib \ site-packages \ robobrowser \ forms \ Site-packages \ robobrowser \ forms \ form.py "to_field 118. Payload.add (field.serialize (), field.payload_key) Exception type: AttributeError  

= "post-text" itemprop = "text">

The issue is how you are setting the value of the form field. To change the value of a field, type your value attribute:

  form.fields ['ln']. Value = name # or, form ['LN'] as a shortcut. Value = name  

Instead of setting the value of the form field, your example code actually replaces the field with the Unicode object form is running ['ln'] = Name ln does not set the value to the name ; It replaces deletion with the ln field and the name string. Then, when the form has to serial its content, Attempts to call the serialize method of each field, but strings do not define the method that leads to the traceback by you.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -