将参数添加到 URL 以在 Python 中迭代

Adding Parameter to URL to Iterate in Python

我有一个正在处理的 Python 脚本,我想在其中循环访问 URL.

末尾的 ID 值列表

到目前为止,这是我的脚本,我想用 ID 值列表替换 url 的 555 部分,这样脚本会为每个值执行 POST。我怎样才能做到这一点?

#/bin/python3
import requests

url = "https://api.bleepbloop.com/v8/account/555"
headers = {"Accept": "application/json", "Authorization": "Bearer 123456"}
response = requests.request("POST", url, headers=headers)
print(response.text)

您可以使用 for 循环,使用 range 函数创建 ID 列表:

#/bin/python3
import requests

base_url = "https://example.com/api/"
headers = {"Accept": "application/json", "Authorization": "Bearer 123456"}
ids = [1,2,3,4] # or range(5)
for id in ids:
    response = requests.request("POST", base_url + str(id), headers=headers)
    print(response.text)

(工作示例:https://replit.com/@LukeStorry/67988932