Python批量注册用户脚本

1.通过Python脚本力量注册用户

import requests
import random


def registerUers():
    # 注册新用户接口
    url = "http://service-xxxxxxxxxxxx.com/member/account/register"
    method = "POST"
    headers = {
        "Authorization" : "Basic xxxxxxxxxxxxxxxx"
    }
    # 需要注册的号码
    userName = randomPhone()
    password = "123456"
    organizationCode = "jianketest"
    # 数据通过表单格式提交
    form_data = {
        "userName": userName,
        "password": password,
        "organizationCode": organizationCode
    }

    response = requests.request(method=method, url=url, headers=headers, data=form_data)
    getUsersinfo = response.json()
    print(response.request)
    print(response.url)
    if response.status_code !=200:
        print(f"响应状态码:{response.status_code}\n")
        print(f"注册失败:\n{response.text}\n")
    else:
        print(f"响应状态码:{response.status_code}\n")
        print(f"注册成功:\n{getUsersinfo}\n")

    return getUsersinfo

def randomPhone():
    '''
    随机生成手机号
    :return:
    '''
    prelist = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "147", "150", "151", "152",
               "153", "155", "156", "157", "158", "159", "186", "187", "188"]
    randomPre = random.choice(prelist)
    Number = "".join(random.choice("0123456789") for i in range(8))
    phoneNum = randomPre +Number

    with open("userName.txt", "a+") as f:
        f.write(f"{phoneNum}\n")
    return phoneNum

if __name__ == "__main__":
    i = 1
    while i < 6:
        print(f"第{i}个号码")
        i = i + 1
        registerUers()

  

posted @ 2022-03-07 14:07  chloe_qq  阅读(2029)  评论(0编辑  收藏  举报