<html>
<head>
<title>Insert Data into DB</title>
</head>
<body>
<hl><br>Insert Data into DB</hl>
<form method="post" action="" name="form1">
<fieldset>
<legend>Slot Status</legend>
<label>slot:<input type="text" name="fname" /></label>
<label>status:<input type="text" name="lname" /></label>
</fieldset>
<br />
<input type="submit" name="submit" value="Update Slot Status" />
</form>
</body>
</html>
Sir above is a simple html form I made and i want to fill this form using python Script.Especially I want to use the mechanize module. Any help will be highly appreciated. Thank You.
Related
what is the proper way to parse multiple .html files within directory, search and remove part of html code in these files?
For example, I need to remove a html code from all files:
<div class="box">
<h2>Book Search</h2>
<div id="search">
<form action="http://www.biology35.com/search.php" method="post">
<input type="text" name="searchfor" class="txtField" />
<input type="image" src="new/images/btn-go.png" name="Submit" value="Submit" class="button" />
<div class="clear"><!-- --></div>
</form>
</div>
</div>
I use Geany 1.29 file editor on Debian. Regex is probably not suitable for this. Some shell script or python?
You can use htql, for example:
html = """
something before
<div class="box">
<h2>Book Search</h2>
<div id="search">
<form action="http://www.biology35.com/search.php" method="post">
<input type="text" name="searchfor" class="txtField" />
<input type="image" src="new/images/btn-go.png" name="Submit" value="Submit" class="button" />
<div class="clear"><!-- --></div>
</form>
</div>
</div>
html after
"""
import htql
x=htql.query(html, "<div norecur (class='box') > &delete ")[0][0]
You get:
>>> x
'\nsomething before\n \n\nhtml after\n'
I'm pretty new to html coding. I am trying to implement a simple application that asks the user to input a salutation, first name, and last name. Upon submission, instead of storing the names into a database, I just want an alert or print statement to appear below the form itself that says "Welcome" + salutation + last name.
I thought I could just implement this using a simple python script and an html file that holds all the contents. Is there something more to this?
app.py
#!/usr/bin/env python3
from flask import Flask, render_template
app = Flask(__name__)
#app.route("/")
def main():
return render_template('form.html')
if __name__ == "__main__":
app.run()
form.html
<html lang="en">
<body>
<div class="container">
<div class="jumbotron">
<h1>Gettin' a feel for docker</h1>
<form class="form" method= "post" onSubmit= "alert('Welcome')">
<label for="salutation" class="sr-only">Salutation</label>
<input type="salutation" name="salutation" id="salutation" class="form-control" required autofocus><br>
<label for="firstName" class="sr-only">First Name</label>
<input type="name" name="firstName" id="firstName" class="form-control" required autofocus><br>
<label for="lastName" class="sr-only">Last Name</label>
<input type="name" name="lastName" id="lastName" class="form-control" required><br>
<button id="submit" class="btn btn-lg btn-primary btn-block" type="button">Submit</button>
</form>
</div>
</div>
</body>
</html>
In order to dynamically display the results of the user input upon a button click, you will have to use jquery.
<html>
<header>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</header>
<body>
<div class='wrapper'>
<input type='text' id='salutation'>
<input type='text' id='firstname'>
<input type='text' id='lastname'>
<button class='get_greeting'>Display</button>
<div class='results'></div>
</div>
</body>
<script>
$(document).ready(function(){
$('.wrapper').on('click', '.get_greeting', function(){
$('.results').html('<p>Welcome, '+$('#salutation').val()+' '+$('#firstname').val()+' '+$('#lastname').val()+'</p>')
});
});
</script>
</html>
The code as per your requirement in form.html should be as follow :
<html lang="en">
<body>
<div class="container">
<div class="jumbotron">
<h1>Gettin' a feel for docker</h1>
<form class="form" method= "post" onSubmit= "alert('Welcome')">
<label for="salutation" class="sr-only">Salutation</label>
<input type="salutation" name="salutation" id="salutation" class="form-control" required autofocus><br>
<label for="firstName" class="sr-only">First Name</label>
<input type="name" name="firstName" id="firstName" class="form-control" required autofocus><br>
<label for="lastName" class="sr-only">Last Name</label>
<input type="name" name="lastName" id="lastName" class="form-control" required><br>
<button id="submit" class="btn btn-lg btn-primary btn-block" type="button" onclick="show_alert()">Submit</button>
</form>
</div>
</div>
<script type="text/javascript">
function show_alert(){
alert("Welcome, "+ document.getElementById('salutation').value + " " + document.getElementById('firstName').value + " " + document.getElementById('lastName').value);
}
</script>
</body>
</html>
In my python for Google App Engine, I have this
MAIN_PAGE_FOOTER_TEMPLATE = """\
<form action="/sign?%s" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
<hr>
<form>Guestbook name:
<input value="%s" name="guestbook_name">
<input type="submit" value="switch">
</form>
</body>
</html>"""
which is used in these functions
self.response.write('<html><body>')
self.response.write(MAIN_PAGE_FOOTER_TEMPLATE %
(sign_query_params, cgi.escape(guestbook_name)))
So I understand that the %s in the top code takes in the parameters provided at the bottom code. However, I am unsure as to how I can do this in a HTML file, rather than coding in python, as it becomes very messy if the HTML code is long. Can anyone help me?
The relevant part of my flask code is:
#app.route("/process", methods = ["GET", "POST"] )
def process_form():
#checked = request.form.getlist('option')
checked=request.form('option')
with open('checked.txt','w') as file:
file.write("%s"%checked)
# do something with checked array
return checked
and my html looks like:
<div class="container" id='tog'>
<div class="half">
<form action="/process" method="POST">
<input type="radio" name="option" value="original" />
<h3>originak value<h3>
</div>
<div class="half">
<input type="radio" name="option" value="freq" />
<h3>Term Freq<h3>
</div>
</form>
</div>
The idea is that I want to find out which radio button was selected and store the information is a text file. But that does not seem to be working.
I changed the html to:
<form action="/process" method="POST">
<div class="half">
<input type="radio" name="option" value="original" />
</div>
<div class="half">
<input type="radio" name="option" value="freq" />
</div>
<input type="submit" value="Submit">
</form>
and now I get a 400 Bad Request error
You don't have a submit button inside of your form. Add one.
<input type="submit" value="Submit!" />
Also, you probably want to change request.form('option') to request.form['option']
I want to enter some text (login, password) inside a page with frames. The structure is something like:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>Whatever</head>
<body id="Body">
<form id="frmM" onsubmit="javascript:return whatever();" action="Login.aspx" method="post">
<div id="alldata">
<div id="header">
<iframe id="Login_SSL" scrolling="no" frameborder="1" src="https://www.whatever.com/User/LoginFrame.aspx?redir=/User/Login.aspx">
<html xmlns="http://www.w3.org/1999/xhtml">
<body onload="refreshParent()">
<form id="form1" action="LoginFrame.aspx?redir=%2fUser%2fLogin.aspx" method="post">
<div id="loginRow" class="loginMenuRow" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'cmdLogin')">
<input id="cmdLogin" type="submit" tabindex="3" onclick="aspnetForm.target ='_top';" value="Login" name="cmdLogin">
<input id="Password" class="textbox" type="password" tabindex="2" name="Password">
<span id="lblPassword" class="loginMenu">Password:</span>
</div>
</form>
</body>
</html>
</iframe>
</div>
</div>
</form>
</body>
</html>
If I try to find the form, I see that only the top level one is available.
>>br.select_form("form1")
FormNotFoundError: no form matching name 'form1'
>>[f.attrs['id'] for f in br.forms()]
['frmM']
How do I go about logging in to this site?
2 options:
Access the URL within the iframe directly and then do your form login
Login to the site from your browser and use an extension like Firebug
to track the posted data. Then replicate this request to login
automatically.