簡體   English   中英

如何從 HTML 用戶輸入獲取數據到 python 文件

[英]How to get the data from the HTML user input to a python file

我一直在嘗試將數據從 HTML 文件獲取到 Python 文件,這里是 HTML 代碼。 我嘗試了 CGI,但我認為它不適合我。 我不知道該怎么做或嘗試什么。

<form class="login100-form validate-form" action="../backenddeneme/main.py" method="post">
                    <span class="login100-form-title">
                        User Login
                    </span>

                    <div class="wrap-input100 validate-input" data-validate = "Username is required">
                        <input class="input100" type="text" name="username" placeholder="Username">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-envelope" aria-hidden="true"></i>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input" data-validate = "Password is required">
                        <input class="input100" type="password" name="pass" placeholder="Password">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-lock" aria-hidden="true"></i>
                        </span>
                    </div>

                    <div class="container-login100-form-btn">
                        <button class="login100-form-btn" type="submit">
                            Login
                        </button>
                    </div>

                    <div class="text-center p-t-12">
                        <span class="txt1">
                            Forgot
                        </span>
                        <a class="txt2" href="#">
                            Username / Password?
                        </a>
                    </div>

                    <div class="text-center p-t-136"></div>
                </form>

我嘗試了這個 python 代碼,但是當我單擊提交按鈕時,出現一個帶有我的 python 代碼的空白頁面

import sqlite3
import cgi

form = cgi.FieldStorage()
username = form.getvalue("username")
password = form.getvalue("password")

conn = sqlite3.connect("users.db")
c = conn.cursor()
c.execute("SELECT * FROM users WHERE username='%s' AND password='%s'" % (username, password))
result = c.fetchall()
print(result)
conn.commit()

conn.close()

嘗試使用 BeautifulSoup 看這里 - https://www.geeksforgeeks.org/implementing-web-scraping-python-beautiful-soup/下載它 - pip install bs4

試試這個<form class="login100-form validate-form" action="/<function name>" method="post">並在服務器端使用 request.form.get 方法來獲取用戶名或密碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM