使用Python使用POST请求登录网站

时间:2020-08-24 23:50:14

标签: python http post networking web-scraping

我正在尝试从以下网站抓取一些数据:https://encompass.com/account。我必须先登录然后获取数据。但是,通过使用chrome开发人员工具检查网络更改,我无法找到POST参数来发送用户名和密码。

我正在使用Python来完成所有这些操作,而且似乎无法弄清楚如何发送用户名和密码参数。

1 个答案:

答案 0 :(得分:1)

要在POST请求中发送json正文,您可以执行以下操作:

import requests

url = 'https://encompass.com/account' # or whatever the endpoint is
credentials = {'user': 'user', 'password': 'password'}

response = requests.post(url, json = credentials)

如果需要,您也可以发送标题,如here

所述