如何使用以下代码制作脚本 python

how to make a script with the following codes python

朋友们晚上好,

我对此 python 代码有疑问。

import requests
resp = requests.post('https://textbelt.com/text', {
  'phone': '5555555555',
  'message': 'Hello world',
  'key': 'textbelt',
})
print(resp.json())

我有一个包含 100 个 phone 个号码的列表,我想用脚本将它们一一发送给所有号码。

也许有一种 smarter/better 的方法来制作代码,我真的不知道。 我怎样才能改变 'phone': '.....' 一个一个地获取数字并执行它。所以不是复制每个数字,有没有办法让它自动?

感谢您的宝贵时间!

你好,

特科斯洛科斯

您应该将 phone 数字存储在 List 中,然后对其进行迭代。

import requests

phone_numbers = [5555555555,6666666666] # all of your phone numbers here

for phone_number in phone_numbers: # for every number, send the sms
    resp = requests.post('https://textbelt.com/text', { 'phone': phone_number, 'message': 'Hello world', 'key': 'textbelt'})