Login using Python in basic HTML form
well first of all check the page code , to know what kind of method so send a data , and the username and password name
<form action="signin.php" method="post" name="log_in" id="log_in" onsubmit="return login()">
<label for="name">User Name:</label><br>
<input type="text" maxlength="80" size="25" id="username" name="username" style="border:1px dotted #1a64a3; margin-bottom:10px">
<label for="email">Password:</label><br>
<input type="password" maxlength="80" size="25" id="password" name="password" style="border:1px dotted #1a64a3">
<input type="submit" name="submit" value="Login" style="background:url(images/submit.gif) no-repeat; width:59px; height:22px; color:#FFFFFF; padding-bottom:3px">
</form>
as you see from above , first we scope to the form ,to see what kind of method and what is the name of fileds
so let's handle it in python
import urllib
login_data=urllib.urlencode({'username':'your username','password':'your password','submit':'Login'}) # replace username and password with filed name
op = urllib.urlopen('www.exmaple.com/sign-in.php',login_data)
Amith KK
21 Years old and an Information Science Student at NMIT. Freelance Full Stack and Web Developer and Editor of the 2buntu Blog. I write poetry in my free time. If you need to get to me, you can find me on Launchpad GitHub LinkedIn
Updated on June 19, 2022Comments
-
Amith KK almost 2 years
Possible Duplicate:
Python: How do you login to a page and view the resulting page in a browser?I wanted to know how I can perform login's on pages like http://www.deshabhimani.com/signin.php which has a php-based login prompt using python. This form is used to login to http://www.deshabhimani.com/epaper.php
The site does not provide a HTTP API.
I want to later use python to download all the pages of the epaper(which are individual) and then make it into a final one file pdf.
The file which I want to download is http://www.deshabhimani.com/epaper.php?page=43210&ddate=27-07-2012&edition=Kochi which is only accessible by logging in
-
Admin almost 12 yearsPlease reduce your code so it only includes what's necessary for a working example.
-
Amith KK almost 12 yearsGreat Answer. I've updated a question a bit to be more clear :D
-
Hamoudaq almost 12 yearswell , if you are looking up for downloading you could use urllib.urlretrieve('URL', 'name')#assign name to the name you want save it with , for exmaple if you download file with name xjxjxj.txt then you assign name to HEELO.txt after downloading it will change to HELLO.txt