I want to submit a form in Python requests. I'm trying to get the list of all members of my organisation from the website.
I've tried the following code:
searchparams={'name':'smith', 'grade':'0', 'format':'html'}
r=requests.post('http://www.thewebsite.co.uk/members/dir/search', data=searchparams)
but it just returns the HTML of the search screen, not the results.
There are also a bunch of other options I could select, but these are the only ones I care about - do I need to submit values for them all?
The form HTML is below, for you information.
<form method="post" action="/members/dir/search" class="col-md-8">
<div class="form-group">
<label for="phone">Surname:</label>
<input type="text" name="name" value="" class="form-control" />
<div class="note">Leave blank to search for all surnames</div>
</div>
<div class="form-group">
<label for="grade">Grade:</label>
<select name="grade" class="form-control">
<option value="0">ALL</option>
<option value="G6">Grade 6</option>
<option value="G7">Grade 7</option>
</select>
</div>
<label>Results format:</label>
<div class="radio">
<label for="format">HTML</label> <input class="tick" type="radio" name="format" value="html" checked="checked" />
</div>
<div class="radio">
<label for="format">Excel</label> <input class="tick" type="radio" name="format" value="excel" />
</div>
<div class="radio">
<label for="format">CSV</label> <input class="tick" type="radio" name="format" value="csv" />
</div>
<div class="form-group">
<button type="submit" name="" class="btn btn-danger">Search</button>
</div>
</form>
Related
I want to fill in a loginForm using BeautifulSoup (I know it's not the easiest way) but I don't know how I can do that. Here under the loginForm.
<form id="loginForm" class="loginContainer" accept-charset="utf-8" action="/wipb2bweb/j_spring_security_check;jsessionid=C647FBABEB8C4ADC3DCCA3C6C875BECC.prod1" method="post"><fieldset>
<legend>Login</legend>
<img src="/wipb2bweb/_ui/themes/carhartt/images/loginTitle.png"
alt="Login" class="title" />
<form>
<div class="formRow">
<label for="User"><img
src="/wipb2bweb/_ui/themes/carhartt/images/loginLabelUser_de.png"
alt="Benutzername" />
</label>
<input id="User" name="j_username" type="text" value=""/></div>
<div class="formRow">
<label for="Password"><img
src="/wipb2bweb/_ui/themes/carhartt/images/loginLabelPass_de.png"
alt="Passwort" />
</label>
<input id="Password" name="j_password" type="password" value=""/></div>
<input type="submit" class="hiddenSubmit"/>
<a href="#" title="Login" class="btnGreyTextured">
<span>Login</span>
</a>
</form>
I am trying to get the input of the forms by just using requests and no actual django form(I do not need to store this data in a database.) So I am trying to use request.GET.get() method, but so far I have had no luck with it. I am pretty sure that it is something wrong with my HTML, but I could be wrong.
Here is my views.py
if request.method == "GET":
lineGraphInp=request.GET.getlist('lineGraphInp')
lineTableInp=request.GET.get('lineTableInp')
print(lineGraphInp)
print(lineTableInp)
Also, here are my forms
<form method="GET">
<h3>Choose: </h3>
<select class="custom-select" name="lineTableInp">
<option value="myPosition">My Position</option>
<option value="myCompetitors">My Competitors</option>
<option value="top100">Top 100</option>
<option value="bottom100">Bottom 100</option>
</select>
</form>
and
<form method="GET">
<h3>Choose: </h3>
<div style="margin-left:15px;">
<div class="form-check form-check-inline">
<input name="lineGraphInp" class="form-check-input" type="checkbox" value="myPosition">
<label class="form-check-label" for="inlineCheckbox1">My Position</label>
</div>
<div class="form-check form-check-inline">
<input name="lineGraphInp" class="form-check-input" type="checkbox" value="myCompetitors" >
<label class="form-check-label" for="inlineCheckbox2">My Competitors</label>
</div>
<div class="form-check form-check-inline">
<input name="lineGraphInp" class="form-check-input" type="checkbox" value="top100">
<label class="form-check-label" for="inlineCheckbox3">Top 100</label>
</div>
<div class="form-check form-check-inline">
<input name="lineGraphInp" class="form-check-input" type="checkbox" value="bottom100">
<label class="form-check-label" for="inlineCheckbox3">Bottom 100</label>
</div>
</div>
</form>
You have not specified form acion
Eg.
<form method="GET" action="/">
Content Here
</form>
Please make sure that you mention that action it will not work unless you will mention it
I think these only a issue..!!!
Thank You
I have created a form in Flask, and want to submit certain values which need to be processed.But the method used is getting defaulted to GET even though I have specified the method as post in my form
These are the the relevant code files:
app.py
#app.route('/test',methods=["GET","POST"])
def test():
print(request.method)
error = None
try:
if request.method == "POST":
first_name = request.form['firstname']
last_name = request.form['lastname']
flash(first_name)
flash(last_name)
return render_template("test.html")
else:
return "Wrong"
except Exception as e:
return str(e)
test.html
<form method="post" class="text-center" style="color: #757575;" action="">
<div class="form-row">
<div class="col">
<!-- First name -->
<div class="md-form">
<input type="text" name="firstname" value="{{request.form.firstname}}" class="form-control">
<label for="materialRegisterFormFirstName">First name</label>
</div>
</div>
<div class="col">
<!-- Last name -->
<div class="md-form">
<input type="text" name="lastname" value="{{request.form.lastname}}" class="form-control">
<label for="materialRegisterFormLastName">Last name</label>
</div>
</div>
</div>
<!-- File Upload -->
<div class="md-form">
<input type="file" id="fileupload" class="form-control">
</div>
<input class="btn btn-info btn-block" type="submit" value="Submit">
</form>
The method is getting defaulted to post and the response "Wrong" on loading 127.0.0.1:5000/test. The method is always GET
<form method="post" class="text-center" style="color: #757575;" action="/test" method="post">
<div class="form-row">
<div class="col">
<!-- First name -->
<div class="md-form">
<input type="text" name="firstname" value="{{request.form.firstname}}" class="form-control">
<label for="materialRegisterFormFirstName">First name</label>
</div>
</div>
<div class="col">
<!-- Last name -->
<div class="md-form">
<input type="text" name="lastname" value="{{request.form.lastname}}" class="form-control">
<label for="materialRegisterFormLastName">Last name</label>
</div>
</div>
</div>
<!-- File Upload -->
<div class="md-form">
<input type="file" id="fileupload" class="form-control">
</div>
<input class="btn btn-info btn-block" type="submit" value="Submit">
</form>
By adding the "route" to the action attribute and defining the method of submission of form, you can perform the desired objective.
Can't figure out why Google won't let me log into my account. I put my email inside a variable called my_mail then search for it in the html but the results came back false.
I am using the requests & beautifulsoup modules to do so.
What I have:
from bs4 import BeautifulSoup
import requests
form_data={'Email': 'ExampleEmail#gmail.com', 'Passwd': 'Password'}
post = "https://accounts.google.com/signin/challenge/sl/password"
my_mail = 'ExampleEmail#gmail.com'
with requests.Session() as s:
soup = BeautifulSoup(s.get("https://accounts.google.com/ServiceLogin?elo=1").text, "html.parser")
for inp in soup.select("#gaia_loginform input[name]"):
if inp["name"] not in form_data:
form_data[inp["name"]] = inp["value"]
s.post(post, form_data)
print(my_mail in "https://mail.google.com/mail/u/0/#inbox")
Form info:
<form novalidate="" method="post" action="https://accounts.google.com/signin/challenge/sl/password" id="gaia_loginform">
<input name="Page" type="hidden" value="PasswordSeparationSignIn">
<input type="hidden" name="GALX" value="c90FYb-yd6E">
<input type="hidden" name="gxf" value="AFoagUVMILWKQvqlGV0i8sJG83jiQlrWzg:1475424777331">
<input id="profile-information" name="ProfileInformation" type="hidden" value="">
<input type="hidden" id="_utf8" name="_utf8" value="☃">
<input type="hidden" name="bgresponse" id="bgresponse" value="js_disabled">
<input type="hidden" id="pstMsg" name="pstMsg" value="1">
<input type="hidden" id="dnConn" name="dnConn" value="">
<input type="hidden" id="checkConnection" name="checkConnection" value="youtube:230:1">
<input type="hidden" id="checkedDomains" name="checkedDomains" value="youtube">
<div class="form-panel first valid" id="gaia_firstform">
<div class="slide-out ">
<div class="input-wrapper focused">
<div id="identifier-shown">
<div>
<label class="hidden-label" for="Email">
Enter your email</label>
<input id="Email" type="email" value="" spellcheck="false" name="Email" placeholder="Enter your email" autofocus="">
<input id="Passwd-hidden" type="password" spellcheck="false" class="hidden">
</div>
</div>
<span role="alert" class="error-msg" id="errormsg_0_Email"></span>
</div>
<div style="display: none" id="identifier-captcha">
<input type="hidden" name="identifiertoken" id="identifier-token" value="">
<input type="hidden" name="identifiertoken_audio" id="identifier-token-audio">
<div class="audio-box">
<div id="playIdentifierAudio"></div>
</div>
<div id="captcha-box" class="captcha-box">
<div id="captcha-img" class="captcha-img" data-alt-text="Visual verification">
</div>
<span class="captcha-msg">
Letters are not case-sensitive
</span>
</div>
<label for="identifier-captcha-input" class="hidden-label"></label>
<input type="text" id="identifier-captcha-input" name="identifier-captcha-input" class="captcha" placeholder="Enter the letters above" title="Type the characters you see or numbers you hear">
</div>
<input id="next" name="signIn" class="rc-button rc-button-submit" type="submit" value="Next">
<a class="need-help" href="https://accounts.google.com/signin/usernamerecovery?hl=en">
Find my account
</a>
</div>
</div>
<a href="https://accounts.google.com/ServiceLogin" tabindex="-1">
<img id="back-arrow" class="back-arrow " aria-label="Back" tabindex="0" alt="Back" src="https://www.gstatic.com/images/icons/material/system/1x/arrow_back_grey600_24dp.png">
</a>
<div class="form-panel second">
<div class="slide-in hide-form">
<div>
<p id="profile-name"></p>
<span id="email-display"></span>
</div>
<div>
<div id="password-shown"></div>
</div>
<input id="signIn" name="signIn" class="rc-button rc-button-submit" type="submit" value="Sign in">
<label class="remember">
<input id="PersistentCookie" name="PersistentCookie" type="checkbox" value="yes" checked="checked">
<span>
Stay signed in
</span>
<div class="bubble-wrap" role="tooltip">
<div class="bubble-pointer"></div>
<div class="bubble">
For your convenience, keep this checked. On shared devices, additional precautions are recommended.
Learn more
</div>
</div>
</label>
<input type="hidden" name="rmShown" value="1">
<a id="link-forgot-passwd" class="need-help" href="https://accounts.google.com/signin/recovery?hl=en">
Forgot password?
</a>
</div>
</div>
<span id="inge" style="display: none" role="alert" class="error-msg">
Sorry, Google doesn't recognize that email. Create an account using that address?
</span>
<span id="timeoutError" style="display: none" role="alert" class="error-msg">
Something went wrong. Check your connection and try again.
</span>
</form>
I don't plan on using Google's API. I don't want to be restricted.
Why is the login failing? What could I do to fix it?
I need to login to scrap some information that requires a login.
Pyhton 3.4.2
I'm a bit confused with all the django stuff and forms, I hope you can help me.
I'm migrating a cmd line app to django, and I think I don't need to mess with models (db) atm. I just would like to pass the parameters filled in a form to a python script that use these fields as parameters. I would like to keep my html code and skip render the form with a python form class since it has a lot of css code inside each one.
At the moment I have this form:
<form class="nobottommargin" id="template-contactform" name="template-contactform" action="{% url 'get_data' %}" method="post">
{% csrf_token %}
<div class="col_half">
<label for="name">Project Name <small>*</small></label>
<input type="text" id="name" name="name" value="{{ current_name }}" class="sm-form-control required" />
</div>
<div class="col_half col_last">
<label for="group">Project Group <small>*</small></label>
<input type="text" id="group" name="group" value="{{ current_group }}" class="required sm-form-control" />
</div>
<div class="clear"></div>
<div class="col_half">
<label for="version">Project Version<small>*</small></label>
<input type="text" id="version" name="version" value="{{ current_version }}" class="required sm-form-control" />
</div>
<div class="col_half col_last">
<label for="pType">Project Type<small>*</small></label>
<select id="pType" name="pType" class="required sm-form-control">
<option value="">-- Select One --</option>
<option value="bundle">Bundle</option>
<option value="multiple">Multiple</option>
<option value="git">Git</option>
</select>
</div>
<div class="col_half">
<label for="pPath">Project path<small>*</small></label>
<input type="text" id="pPath" name="pPath" value="{{ current_path }}" class="required sm-form-control" />
</div>
<div class="clear"></div>
<div class="col_full hidden">
<input type="text" id="template-contactform-botcheck" name="template-contactform-botcheck" value="" class="sm-form-control" />
</div>
<div class="col_full" style="margin: 50px 0 0 0 ">
<button class="button button-3d nomargin" type="submit" id="template-contactform-submit" name="template-contactform-submit" value="submit">Create Project</button>
</div>
</form>
So, I want to figure out what's the best way to write the get_data function. I also need some sort of custom validation about some fields that involves other checks that exceeds the basic checks, such as max_chars on each field. That means I need to create some sort of my own form.is_valid() function.
Hope you can help me!
Regards