Skip to content

Commit

Permalink
更改输出,便于阅读
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroWolf233 committed Aug 27, 2024
1 parent 6eb13dc commit 26c91ff
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,32 @@ def send_request(url, headers, rest, i):

# 检查请求是否成功
if response.status_code == 200:
print(f"\n请求 {i + 1} 成功,最终服务器地址: {response.url}\n")
print(f"\n请求 {i + 1} 成功,最终服务器地址: {response.url}\n\n"+"-"*100+"\n")
else:
print(f"请求 {i + 1} 失败,状态码: {response.status_code}\n")
print(f"请求 {i + 1} 失败,状态码: {response.status_code}\n\n"+"-"*100+"\n")

except requests.exceptions.RequestException as e:
print(f"请求 {i + 1} 失败,发生异常: {e}\n")
print(f"请求 {i + 1} 失败,发生异常: {e}\n\n"+"-"*100+"\n")

# 每次请求后休息指定时间
time.sleep(int(rest))

def get_valid_int_input(prompt, default):
while True:
user_input = input(prompt)
if not user_input:
return default
try:
return int(user_input)
except ValueError:
print("杂鱼杂鱼,是无效的输入呢~\n")

def main():
url = input('请求地址:')
num_requests = int(input('请求次数(默认10次):') or 10)
num_requests = get_valid_int_input('请求次数(默认10次):', 10)
ua = input('UA(不输入我就用默认的):') or "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0"
rest = int(input('请求间隔(单位:秒)(仅支持整数)(默认3秒):') or 3)
workers = int(input('要多少线程(嘿嘿)(默认1个线程):') or 1)
rest = get_valid_int_input('请求间隔(单位:秒)(仅支持整数)(默认3秒):', 1)
workers = get_valid_int_input('要多少线程(嘿嘿)(默认1个线程):', 1)
print('\n')

headers = {"User-Agent": ua}
Expand Down

0 comments on commit 26c91ff

Please sign in to comment.