【问题标题】:Creating HTTP post requests with data in python/ [duplicate]在 python/ 中使用数据创建 HTTP 发布请求 [重复]
【发布时间】:2021-06-24 15:04:21
【问题描述】:

如果我想通过 python 函数手动向网站发送包含我的用户名和密码数据的发布请求。可能吗?如果是这样,一些示例代码会是什么。

以下是一些半途而废的代码,因为我对http requests 没有经验:

import requests
payload = {"username":"anton","password":"password"}

r = requests.post('https://www.walmart.com/account/login', data = payload)

print(r.text)

【问题讨论】:

标签: python http automation http-headers bots


【解决方案1】:

这应该可以完成工作:

import requests

url = "your_url"
r = requests.post(url, auth=("your_username", "your_password"))

print(r.text)

更多信息请参见requests docs

【讨论】:

    猜你喜欢
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 2016-10-27
    • 2023-03-11
    相关资源
    最近更新 更多