Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.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中的某个xyz文件中_Python_Html_Cgi - Fatal编程技术网

在从html表单获取值的文件中搜索数据,并将其存储在python中的某个xyz文件中

在从html表单获取值的文件中搜索数据,并将其存储在python中的某个xyz文件中,python,html,cgi,Python,Html,Cgi,我有一个html文件,上面有一个人的详细信息,如名字、姓氏、年龄、性别。 我有一个python文件,它从这些html文件中获取数据并将其保存在某个xyz文件中。 现在我想要一个搜索按钮,通过它,如果我在文本框中输入任何内容,就可以通过文件进行搜索 my index.html文件: <html> <head> <title>INFORMATION</title> </head> <body> <form ac

我有一个html文件,上面有一个人的详细信息,如名字、姓氏、年龄、性别。
我有一个python文件,它从这些html文件中获取数据并将其保存在某个xyz文件中。
现在我想要一个搜索按钮,通过它,如果我在文本框中输入任何内容,就可以通过文件进行搜索

my index.html文件:

<html>
<head>
<title>INFORMATION</title>
</head>
  <body>
    <form action = "/cgi-bin/test.py" method = "post">
    FirstName:
    <input type = "text" name = "firstname" /><br>
    LastName:
    <input type = "text" name = "lastname" /><br>
    <input type = "submit" name = "submit "value = "SUBMIT">
    <input type = "reset" name = "reset" value = "RESET">
    <input type = "button" name = "search" value = "SEARCH">
    </form>
 </body>
</html>

现在,我应该编写什么来在python代码中进行搜索?我将不知道该写什么?

如果您需要在刚创建的文件中搜索一个单词:

with open('file.txt', 'r') as f:
for line in f:
    if 'wordToLookFor' in line:
        print "found it in : %s" % line

我不知道csv文件。此外,我刚刚开始学习pythonth,它很好,我在下面发布了答案……不,@louhibi先生,这不是一个可行的解决方案,如果您知道
搜索字符串以及它在文件中的存在,那么,从文件中存储和搜索有什么用呢?我必须说,这个问题对我来说仍然模棱两可:)@mrlouhibi:问题是直截了当的。我在html中有一个搜索按钮,如果在任何文本字段中输入任何内容并单击搜索,它将在文件中搜索您刚刚保存的abc.txt文件?如果是这样的话,那么我的解决方案是有效的。你能建议我在test.py代码中把你的代码写在哪里吗??
with open('file.txt', 'r') as f:
for line in f:
    if 'wordToLookFor' in line:
        print "found it in : %s" % line