0

I've been trying to get the data from an HTML file to a Python file, here is the HTML code. I tried CGI but I don't think it works for me. I don't know what to do or what to try.

<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>

I tried this python code but when I click the submit button, a blank white page with my python code appears

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()
1
  • 1
    You need to be more specific. What code have you tried so far for the data extraction? Please add it to the question itself. Commented Jun 14, 2020 at 16:26

2 Answers 2

1

Try using BeautifulSoup Look here - https://www.geeksforgeeks.org/implementing-web-scraping-python-beautiful-soup/ To download it - pip install bs4

Sign up to request clarification or add additional context in comments.

1 Comment

As I know bs4 is used to get HTML data from a website, I need the input data from my website. I don't think I can use bs4 because of that.
0

try this <form class="login100-form validate-form" action="/<function name>" method="post"> and on the server side use request.form.get method to get the username or password

4 Comments

There isn't any server side for me, I'm working on this project and I run it on a python HTTP server
Sorry I was assuming you were using Flask framework
How can I use that Flask framework and is it good? Because I think I can't run a python file in my localhost because of python's http.server does not support SQL
Flask is great, You can run it in your local host, you can try flask development server to connect SQL database too. you have to install Flask and read their official doccs to use it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.