python答题xxqg_Python数据擦除表单身份验证问题

下面是一些代码,我一直试图使用这些代码登录到cook'sIllustrated网站(https://www.cooksillustrated.com/sign_in)。在

我启动一个会话,获取身份验证令牌和一个隐藏的编码字段,然后传递email和password字段的“name”和“value”(通过检查chrome中的元素找到)。表单似乎不包含任何其他元素;但是,post方法不让我登录。在

我注意到所有CSRF标记都以“==”结尾,所以我尝试删除它们。但没用。在

我还尝试修改post以使用表单输入的“id”字段而不是“name”(只是一个模糊的例子,真的…name似乎应该可以从我在其他示例中看到的情况下使用)。在

任何想法都将不胜感激。在import requests, lxml.html

s = requests.session()

# go to the login page and get its text

login = s.get('https://www.cooksillustrated.com/sign_in')

login_html = lxml.html.fromstring(login.text)

# find the hidden fields names and values; store in a dictionary

hidden_inputs = login_html.xpath(r'//form//input[@type="hidden"]')

form = {x.attrib['name']: x.attrib['value'] for x in hidden_inputs}

print(form)

# I noticed that they all ended in two = signs, so I tried taking that off

# form['authenticity_token'] = form['authenticity_token'][:-2]

# this adds to the form payload the two named fields for user name and password

# found using the "inspect elements" on the login screen

form['user[email]'] = 'my_email'

form['user[password]'] = 'my_pw'

# this uses "id" instead of "name" from the input fields

#form['user_email'] = 'my_email'

#form['user_password'] = 'my_pw'

response = s.post('https://www.cooksillustrated.com/sign_in', data=form)

print(form)

# trying to see if it worked - but the response URL is login again instead of main page

# and it can't find my name

# responses are okay, but I think that just means it posted the form

print(response.url)

print('Christopher' in response.text)

print(response.status_code)

print(response.ok)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值