1 Star 3 Fork 1

星冉/sites-py

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.py 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
星冉 提交于 2020-06-21 17:56 . update
#! /usr/bin/python3
# -*- coding: UTF-8 -*-
import requests
import time
header = {"User-Agent": "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"} # 新增百度蜘蛛头
# r1 = requests.get('https://www.zygd.site', timeout=10, headers=header)
def site_test(timeout):
r1 = requests.get(i, timeout=timeout, headers=header, verify=True) #
print(r1.url, r1.reason, r1.elapsed, r1.status_code, r1.encoding, r1.headers['Server']) # 最终地址 响应状态描述请求时间 请求状态值 自动编码检测
with open("sites.txt", 'r') as sites:
for i in sites.readlines():
try:
site_test(1)
except IOError:
try:
site_test(5)
except IOError:
try:
print(i, ' 站点异常正在重试...')
site_test(10)
except IOError:
times = time.strftime("%m-%d-%H:%M:%S", time.localtime())
with open("log.txt", 'a', encoding="UTF-8") as log:
log.write(times + ' ' + i + ' ' + "访问异常\n")
print(i, ' 访问异常', ' 请查看日志文件!')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/XRSec/sites-py.git
git@gitee.com:XRSec/sites-py.git
XRSec
sites-py
sites-py
master

搜索帮助