You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
python-project/os/nginx-request.py

22 lines
716 B

import requests
import time
'''
第一次运行,在终端中运行
yum install -y python3
pip3 install requests
'''
# 页面请求
def main(url=None,number=100,sleep=0):
n = time.time()
for i in range(1,number + 1):
now = time.time()
r = requests.get(url)
data = {"请求": i,"状态": r.status_code,"耗时": f"{int((time.time() - now) * 1000)}ms","总耗时": f"{int((time.time() - n) * 1000)}ms"}
time.sleep(sleep)
print(data)
print("请求数:",number,"总耗时:", int((time.time() - n) * 1000),'ms')
if __name__ == "__main__":
# main(url="请求链接",number=请求次数,sleep=请求间隔)
main(url="http://gitea.beyourself.org.cn",number=100)