python - 如何在没有登录表单页面的情况下进行现场授权?
问题描述
如何在没有登录表单页面的情况下进行现场授权。该站点使用带有 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>
解决方案
尝试这个:
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/
推荐阅读
- java - 反序列化 ArrayList:[unchecked] 需要未经检查的转换:ArrayList
找到:数组列表 - r - 使用 tsclean 从 R 中的多个时间序列中删除异常值
- java - 类似 PuTTy 的 Java SSH 客户端
- java - 使用流 api 或 lambda 从管道分隔字符串中过滤特定列
- node.js - Dialogflow agent.add 不使用承诺
- c# - 如何解决“System.Windows.Forms.dll 中发生'System.ComponentModel.Win32Exception' 类型的未处理异常”?
- php - WP_Query 按标签搜索
- reactjs - React Typescript - 类型参数不可分配给类型参数
- jquery - 为什么即使在安装和导入依赖项之后,bootstrap 4 下拉和切换按钮也不起作用?
- angular - 角度选择值字符串解析为整数