首页 > 解决方案 > 如何在没有登录表单页面的情况下进行现场授权?

问题描述

如何在没有登录表单页面的情况下进行现场授权。该站点使用带有 url 的模态表单,例如http://example-site.com/#myModal

我试过了:

s = requests.Session()
data = {"login_name":"admin", "login_password":"password"}
url = "http://example-site.com/#myModal"
r = s.post(url, data=data, headers={'User-Agent': 'Mozilla/5.0'})
html = s.get('http://example-site/forauthorizedusers.html',headers={'User-Agent': 'Mozilla/5.0'} )
print(html.text)

在这段代码的结果中,我得到了非授权用户的 html 页面。

网站的HTML代码是:

form class="form-inline" method="post" action="">
<input type="text" name="login_name" id="login_name" class="input-small" style="margin-top: -2px;" placeholder="Login">
<input type="password" name="login_password" id="login_password" style="margin-top: -2px;"  class="input-small" placeholder="Password">                                                                                                                                                                                                                 
<button style="margin-bottom: 0px;margin-top: -2px;margin-left: 0px;" type="submit" nclick="submit();" class="btn btn-info " >Log in</button>
<input name="login" type="hidden" id="login" value="submit" />
</form>

标签: pythonpython-requests

解决方案


尝试这个:

html = s.get('http://example-site/forauthorizedusers.html', auth=HTTPBasicAuth('admin', 'password'), headers={'User-Agent': 'Mozilla/5.0'})

http://docs.python-requests.org/en/master/user/authentication/


推荐阅读