直接上代码
import requests
import time
import asyncio
import aiohttp
import random
a = 0
url = 'http://97.64.124.57/api/user/get_filter_conditions' # worker 1
url = 'http://97.64.120.30:8080/api/user/get_filter_conditions' # worker 2
url = 'https://www.eosask.com/api/user/get_filter_conditions'
url = 'http://97.64.33.19/api/user/get_filter_conditions' # nginx
# url = 'https://www.cryptocpi.com/api/user/get_filter_conditions'
# url = 'https://www.baidu.com'
#url = 'https://bwh1.net/'
def create_phone():
# 第二位数字
second = [3, 4, 5, 7, 8][random.randint(0, 4)]
# 第三位数字
third = {
3: random.randint(0, 9),
4: [5, 7, 9][random.randint(0, 2)],
5: [i for i in range(10) if i != 4][random.randint(0, 8)],
7: [i for i in range(10) if i not in [4, 9]][random.randint(0, 7)],
8: random.randint(0, 9),
}[second]
# 最后八位数字
suffix = random.randint(9999999, 100000000)
# 拼接手机号
return "86" + "1{}{}{}".format(second, third, suffix)
start = time.time()
async def post_test(_):
async with aiohttp.ClientSession() as session:
phone = create_phone()
# async with session.post('https://www.eosask.com/api/user/register',
# data={'username': phone,
# 'password': "",
# 're_password': "",
# 'code': 111111}) as resp:
async with session.get(url) as resp:
global a
a = a + 1
print(resp.status, a)
#print(await resp.text())
tasks = [asyncio.ensure_future(post_test(_)) for _ in range(500)]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))
# for i in range(100):
# requests.get(url)
# print(i)
end = time.time()
print('Cost time:', end - start)



