问题
I have a form with a textarea and need to submit multiple lines of input to the textarea.
I use :
rows = [('a','b'), ('c','d')]
data_set = [ '%s\n' % '|'.join(row) for row in rows ] # Note : ADDED '\n'
data_dump = ''.join(data_set)
from mechanize import Browser
br = Browser()
br.open('http://example.com/page.html')
br.select_form(nr=1)
br.form['my_text_area']=data_dump
br.submit()
Problem:
- Webserver is not able to see the input as multiple lines.
- ADDED
\nis not working for simulating line breaks in the inputs.
What am I doing wrong ?
Feel free to ask for more info if I have missed something !
Update
I also tried \n\r in place of \n, but the problem persists.
回答1:
I figured it out with the help of https://stackoverflow.com/users/87015/salman-a
CR = \r
LF = \n
And HTML forms take a line-break as CRLF, so therefore :
\r\n worked !
来源:https://stackoverflow.com/questions/9456170/how-to-handle-line-breaks-in-html-forms