python 虚拟账号注册用户

  1 import requests
  2 import json
  3 import random
  4 from bs4 import BeautifulSoup
  5 
  6 import time
  7 
  8 import re
  9 
 10 # 获取验证码
 11 
 12 
 13 def get_code(url):
 14     print('连接https://www.materialtools.com'+url)
 15     time.sleep(15)
 16     content = requests.get('https://www.materialtools.com'+url).text
 17     b = re.findall(
 18         r'(d+)获取验证码的正则', content, flags=0)
 19     if(b):
 20         return b[0]
 21     return False
 22 
 23 
 24 def number_list():
 25     content = requests.get('https://www.materialtools.com/?page=13').text
 26     con = BeautifulSoup(content,  "html.parser")
 27     list = con.select(
 28         '.container-fluid > .show-grid ')
 29     for item in list:
 30         i = item.select(
 31             '.number-list-phone_number > .phone_number-text > h3')
 32         b = item.select('.sms-number-read > a')
 33         for c in i:
 34             phone = c.string
 35         for i in b:
 36             href = i['href']
 37 
 38         print('手机号为'+phone)
 39 
 40         # 发送手机验证码
 41         res = phone_send_number(phone)
 42         if res['code'] == 0:
 43             # if True:
 44             print('短信发送成功了')
 45             code = get_code(href)
 46             if code:
 47                 reg(phone, code)
 48             else:
 49                 print('验证码获取失败')
 50                 continue
 51         else:
 52             print('验证码发送失败')
 53             continue
 54 
 55 
 56 def gen_headers(s):
 57     ls = s.split('
')
 58     lsl = []
 59     ls = ls[1:-1]
 60     headers = {}
 61     for l in ls:
 62         l = l.split(': ')
 63         lsl.append(l)
 64     for x in lsl:
 65         headers[x[0].strip('    ')] = x[1]
 66     return headers
 67 
 68 
 69 def phone_send_number(phone):
 70     headerstr = '''
 71         Content-Type: application/json;charset=UTF-8
 72         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
 73         X-Token: ''
 74     '''
 75     req = {
 76         'phone': phone,
 77         'sms_type': '10'
 78     }
 79     header = gen_headers(headerstr)
 80 
 81     res = requests.post('发送验证码的地址',
 82                         data=json.dumps(req), headers=header).json()
 83     return res
 84 
 85 
 86 def reg(phone, code):
 87     headerstr = '''
 88         Content-Type: application/json;charset=UTF-8
 89         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
 90         X-Token: ''
 91     '''
 92     name = random.randint(100000, 99999999)
 93     header = gen_headers(headerstr)
 94     reg_req = {
 95         'inviter_phone': "",
 96         'password': "666666",
 97         'phone': phone,
 98         'sms_code': code,
 99         'username': "hjkshf"+str(name),
100     }
101 
102     res = requests.post('你的url',
103                         data=json.dumps(reg_req), headers=header).json()
104 
105     if res['code'] == 0:
106         print('手机号为'+phone+'验证码为'+code+'注册成功')
107         fo = open("foo.txt", "a+")
108         fo.write(phone+"
")
109         fo.close()
110     else:
111         print('手机号'+phone+'注册失败')
112 
113 
114 number_list()
原文地址:https://www.cnblogs.com/chengfengchi/p/12166281.html