python获取http状态码
2021-01-14 00:12
标签:__name__ sleep import example while 获取 超过 int code python获取http状态码 标签:__name__ sleep import example while 获取 超过 int code 原文地址:https://blog.51cto.com/liuxiaolan/2497765#!/bin/env python
# -*- coding: UTF-8 -*-
# Author: 刘小懒
# example: python http_status.py ota_list
import requests
import time
import sys
from threading import Thread
def http_status(arg):
try:
html = requests.get(arg)
codes = html.status_code
a = 0
while True:
if codes == 200:
print("t0", codes)
return codes
else:
a = a+1
time.sleep(5)
if a >= 3:
print(codes)
return codes
except:
sys.exit(0)
if __name__ == "__main__":
code = sys.argv[1]
http_url = {
"baidu": "www.baidu.com",
"tmail": "https://www.tmail.com"
}
for i in http_url.keys():
if code in i:
http_url = http_url.get(i)
t = Thread(target=http_status, args=(http_url,))
t.start()
下一篇:排序链表