且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Python以基本HTML格式登录

更新时间:2023-12-05 14:18:16

首先检查页面代码, 知道发送数据的方法以及用户名和密码名

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

所以让我们在python中处理它

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)