【问题标题】:Python requests. Emulating cookiesPython 请求。模拟 cookie
【发布时间】:2020-11-06 00:53:29
【问题描述】:

我正在尝试抓取网络,但作为输出,AADSTS165000: Invalid Request 出现错误。

我的 Python 代码非常简单:

import requests
s = requests.session()
link = 'https://login.microsoftonline.com/.../login'
email = {'loginfmt':'...',
             'passwd':'...',}
loging = s.post(link, data = email)

f = open('123.txt', 'w')
f.write(loging.text)
f.close()

但是通过The request did not return all of the form fields. Failure Reasons:[Missing session context cookie;Token was not provided;]获取html输出

如何模拟成功登录并获取 html 的所有要求?

【问题讨论】:

  • This 可能会回答您的问题。它解决了如何使用 requests 获取会话 cookie。

标签: python html web web-scraping python-requests


【解决方案1】:

要将 cookie 注入您的请求,您需要准备好 cookie,

假设你已经有了,

cookies = {"key":"value"}
loging = s.post(link, data = email, cookies=cookies)

【讨论】:

    【解决方案2】:

    您可能需要在登录后获取会话 cookie,并将其与您的下一个请求一起发送。

    也是这样

    cookies = s.cookies.get_dict()
    loging = s.post(link, data = email, cookies=cookies)
    

    【讨论】:

      猜你喜欢
      • 2013-04-10
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 2021-12-02
      相关资源
      最近更新 更多