繁体   English   中英

Python:使用“请求”模块登录到网站

[英]Python: Log in to a website using Requests module

我正在尝试使用请求模块登录网站并获取登录页面的html。 我对这些东西不熟悉,因此找不到适合的教程。 这是我所拥有的有关登录表单页面HTML的信息(URL: http : //14.139.251.99 : 8080/jopacv06/ html/ checkouts

<FORM NAME="form" METHOD="POST" ACTION="./memberlogin" onsubmit="this.onsubmit= function(){return false;}">


<table class='loginTbl' border='1' align="center" cellspacing='3' cellpadding='3' width='60%'>
   <input type="hidden" name="hdnrequesttype" value="1" />
   <thead>
   <tr>
    <td colspan='3' align="middle" class='loginHead'>Login</td>
   </tr>
   </thead>

   <tbody class='loginBody'>

   <tr>
    <td class='loginBodyTd1' nowrap="nowrap">Employee ID</td>
    <td class='loginBodyTd2'><input type='text' name='txtmemberid' id='txtmemberid' value='' class='loginTextBox' size='30' maxlength='8'/></td>
    <td class='loginBodyTd3' rowspan='2'><input type="submit" class="goclearbutton" value="  Go  "></td>
   </tr><input type='hidden' name='txtmemberpwd' id='txtmemberpwd' value='' />

   </tbody>

   <tfoot>
    <tr>
        <td colspan='3' class='loginFoot'>
            <font class='loginRed'>New Visitor?</font>

            <a href="mailto:admin@libsys.co.in?subject=New Registration&body=New Registartion Request">Send</a> your registration request to library !

           </td>
       </tr>
   </tfoot>

   </table>
   </form>

我知道我可能需要设置cookie,因此登录页面中的cookie名称是JSESSIONID(以防万一,这是必需的)。 我发现,一旦我成功登录,就必须使用beautifulSoup来获取详细信息。 请帮助我如何将这些部分组合在一起。

你将不得不做这样的事情,

import requests

response = requests.post("http://14.139.251.99:8080/jopacv06/html/checkouts/memberlogin", data = {'txtmemberid': '1'})

if response.status_code == 200:
    html_code = response.text
// Do whatever you want to do further with this HTML now.    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM