python 虚拟账号注册用户

import requests
import json
import random
from bs4 import BeautifulSoup

import time

import re

# 获取验证码


def get_code(url):
    print(‘连接https://www.materialtools.com‘+url)
    time.sleep(15)
    content = requests.get(‘https://www.materialtools.com‘+url).text
    b = re.findall(
        r‘(\d+)获取验证码的正则‘, content, flags=0)
    if(b):
        return b[0]
    return False


def number_list():
    content = requests.get(‘https://www.materialtools.com/?page=13‘).text
    con = BeautifulSoup(content,  "html.parser")
    list = con.select(
        ‘.container-fluid > .show-grid ‘)
    for item in list:
        i = item.select(
            ‘.number-list-phone_number > .phone_number-text > h3‘)
        b = item.select(‘.sms-number-read > a‘)
        for c in i:
            phone = c.string
        for i in b:
            href = i[‘href‘]

        print(‘手机号为‘+phone)

        # 发送手机验证码
        res = phone_send_number(phone)
        if res[‘code‘] == 0:
            # if True:
            print(‘短信发送成功了‘)
            code = get_code(href)
            if code:
                reg(phone, code)
            else:
                print(‘验证码获取失败‘)
                continue
        else:
            print(‘验证码发送失败‘)
            continue


def gen_headers(s):
    ls = s.split(‘\n‘)
    lsl = []
    ls = ls[1:-1]
    headers = {}
    for l in ls:
        l = l.split(‘: ‘)
        lsl.append(l)
    for x in lsl:
        headers[x[0].strip(‘    ‘)] = x[1]
    return headers


def phone_send_number(phone):
    headerstr = ‘‘‘
        Content-Type: application/json;charset=UTF-8
        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
        X-Token: ‘‘
    ‘‘‘
    req = {
        ‘phone‘: phone,
        ‘sms_type‘: ‘10‘
    }
    header = gen_headers(headerstr)

    res = requests.post(‘发送验证码的地址‘,
                        data=json.dumps(req), headers=header).json()
    return res


def reg(phone, code):
    headerstr = ‘‘‘
        Content-Type: application/json;charset=UTF-8
        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
        X-Token: ‘‘
    ‘‘‘
    name = random.randint(100000, 99999999)
    header = gen_headers(headerstr)
    reg_req = {
        ‘inviter_phone‘: "",
        ‘password‘: "666666",
        ‘phone‘: phone,
        ‘sms_code‘: code,
        ‘username‘: "hjkshf"+str(name),
    }

    res = requests.post(‘你的url‘,
                        data=json.dumps(reg_req), headers=header).json()

    if res[‘code‘] == 0:
        print(‘手机号为‘+phone+‘验证码为‘+code+‘注册成功‘)
        fo = open("foo.txt", "a+")
        fo.write(phone+"\n")
        fo.close()
    else:
        print(‘手机号‘+phone+‘注册失败‘)


number_list()

相关推荐