Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将字符串从html传递到python脚本_Python_Html_String_Web - Fatal编程技术网

将字符串从html传递到python脚本

将字符串从html传递到python脚本,python,html,string,web,Python,Html,String,Web,我需要帮助,我有一个Python脚本,可以做一些工作并打印html网页。 我需要将字符串从输出的网页传递到该脚本。 可能吗? 在将来,我想使用单选按钮,用户将从预定义的数据中获取用于打印的厚数据。 谢谢你的建议 我的代码: #!/usr/bin/env python # -*- coding: UTF-8 -*- # enable debugging import cgitb cgitb.enable() import subprocess import os print "Content-

我需要帮助,我有一个Python脚本,可以做一些工作并打印html网页。 我需要将字符串从输出的网页传递到该脚本。 可能吗? 在将来,我想使用单选按钮,用户将从预定义的数据中获取用于打印的厚数据。 谢谢你的建议

我的代码:

#!/usr/bin/env python 
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
import subprocess
import os

print "Content-type: text/html\n\n";
web = """

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>

</head>
<body>
    <div id='wrapper'>
        <div id='header'>

        </div>

        <div id='content'>
            <div class='content'>
                <div><h3>GRAPH</h3></div>
                <br>
                <div style='height:520px;width:1000px;overflow:scroll;overflow-x:auto;overflow-y:hidden;'>
                    <img src='http://localhost/steps.png' alt='image' />
                </div>
                <br>    
                <button onclick="myFunction()">REFRESH</button>
                <script>
                    function myFunction() {
                    location.reload();
                    }
                </script>

                <br>

                <form action='/cgi-bin/test.py' method='post'>
                    nazov suboru: <input type='text' data='data'> <br />
                <input type='submit' value='Submit' />
                </form>


            </div>
        </div>
    </div>          
</body>
</html>
"""

print web
proc = subprocess.Popen(['gnuplot','-p'], 
                        shell=True,
                        stdin=subprocess.PIPE,
                        )

proc.communicate("""
reset
set terminal pngcairo enhanced size 3000,500 font 'Arial,11' rounded; 
set output '/opt/lampp/htdocs/%s.png'

set datafile separator "|"
plot \
\
'%s.txt' u 0:3 sm cs w l ls 1  t 'X-suradnice',\
'%s.txt' u 0:4 sm cs w l ls 2  t 'Y-suradnice',\
'%s.txt' u 0:5 sm cs w l ls 3  t 'Z-suradnice'
"""%(data,data,data,data)) 

您的问题很难理解,但我认为您正在尝试解决如何访问表单POST提交的数据参数。您可以通过cgi模块实现这一点:


我对这真的很陌生。有什么简单的方法吗?我的意思是以某种方式保存到用户写的字符串@tdelaney肯定不是在问刮削,而是在问如何在CGI脚本中提交文本字段。
import cgi
form = cgi.FieldStorage()
data = form.getvalue('data')