简体   繁体   English

如何处理HTML表单中的换行符?

[英]How to handle line-breaks in HTML forms?

I have a form with a textarea and need to submit multiple lines of input to the textarea . 我有一个formtextarea ,需要输入多行提交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. Web服务器无法将输入视为多行。
  • ADDED \\n is not working for simulating line breaks in the inputs. 添加\\n不适用于模拟输入中的换行符。

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. 我也尝试用\\n\\r代替\\n ,但是问题仍然存在。

I figured it out with the help of https://stackoverflow.com/users/87015/salman-a 我在https://stackoverflow.com/users/87015/salman-a的帮助下弄清楚了

CR = \\r LF = \\n CR = \\ r LF = \\ n

And HTML forms take a line-break as CRLF , so therefore : HTML表单的换行符为CRLF ,因此:

\\r\\n worked ! \\r\\n有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM