How to handle line-breaks in HTML forms?

孤街醉人 提交于 2019-12-11 04:12:55

问题


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 \n is 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!