使用ASPX网站上的请求的身份验证问题 [英] Authentication issue using requests on aspx site

查看:97
本文介绍了使用ASPX网站上的请求的身份验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用请求(python)从需要我登录的网站上获取某些页面. 我确实检查了登录页面以检查用户名和密码标题.但是我发现这些字段的名称不是大多数网站使用的标准用户名",密码",如下面的屏幕截图所示

I am trying to use requests (python) to grab some pages from a website that requires me to be logged in. I did inspect the login page to check out the username and password headers. But I found the names for those fields are not the standard 'username', 'password' used by most sites as you can see from the below screenshots

密码字段

我在python脚本中以这种方式使用了它们,但是每次遇到语法错误"错误时,都会使用它们.从下面的pix中可以看到,甚至sublimetext也以橙色显示了名称的一部分

I used them that way in my python script but each time I get a 'wrong syntax' error. Even sublimetext displayed a part of the name in orange as you can see from the pix below

据此,我知道名称一定有问题.但是尝试逃脱$符号没有帮助. 甚至在login.aspx标头消失之前,谷歌浏览器可以在网络上注册它.

From this I know there must be some problem with the name. But try to escape the $ signs did not help. Even the login.aspx header disappears before google chrome could register it on the network.

该站点是www dot bncnetwork dot net

The site is www dot bncnetwork dot net

如果有人可以帮助我弄清楚该怎么办,我会很高兴.

I'd be happy if someone could help me figure out what to do about this.

这是代码的导入请求

import requests

def get_project_page(seed_page):

   username = "*******************"
   password = "*******************"

   bnc_login = dict(ctl00$MainContent$txtEmailID=username, ctl00$MainContent$txtPassword=password)
   sess_req = requests.Session()
   sess_req.get(seed_page)
   sess_req.post(seed_page, data=bnc_login, headers={"Referer":"http://www.bncnetwork.net/MyBNC.aspx"})

page = sess_req.get(seed_page)

return page.text`

推荐答案

您需要使用字符串作为键,否则,$将导致语法错误:

You need to use strings for the keys, the $ will cause a syntax error if you don't:

  data = {"ctl00$MainContent$txtPassword":password, "ctl00$MainContent$txtEmailID":email}

甚至还要填写验证文件等.请遵循此

There are evenvalidation fileds etc.. to be filled in also, follow the logic from this answer to fill them out, all the fields can be seen in chrome tools:

这篇关于使用ASPX网站上的请求的身份验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆