代码拉取完成,页面将自动刷新
#! /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, ' 访问异常', ' 请查看日志文件!')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。