如何处理HTML表单中的换行符? [英] How to handle line-breaks in HTML forms?

查看:356
本文介绍了如何处理HTML表单中的换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单和一个 textarea ,需要将多行输入提交到 textarea



我用:

  rows = [('a','b'),('c','d')] 
data_set = ['%s\\\
'%'|'.join(row)for row in row]#注意:ADDED'\\\
'
data_dump =''.join(data_set)
$ b $ from机械化导入浏览器
br =浏览器()
br.open('http://example.com/page.html')
br.select_form(nr = 1)
br.form ['my_text_area'] = data_dump
br .submit()

问题:


  • Webserver无法将输入视为多行。
  • ADDED \\\
    不起作用用于模拟输入中的换行符。



我做错了什么?



如果我错过了一些东西,请随时索取更多信息!

更新



我也试过 \\\
\r
来代替 \\\
,但问题仍然存在。

解决方案

我在https://stackoverflow.com/users/87015/salman-a



CR = \ r
LF = \ n



换行符为 CRLF ,因此:



\r\\\
工作!


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.

解决方案

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 !

这篇关于如何处理HTML表单中的换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆