博客的友链不时会出现死链,网站打不开等的状态,本来想着用 UptimeRobot 这类网站监控工具来监控但是手动同步友链列表又比较麻烦,所以就改为用 n8n 工作流来定时自动获取友情链接列表,再自动逐一检测状态并筛选失效链接推送,用了点时间弄出来一个工作流,如果你有类似需求可以参考看看 🙂
n8n 工作流
先看截图:

逐一说明:
- 定时触发:每 10 小时触发运行
- HTTP 请求:发送请求到博客的友链页面(https://wuminboke.site/misc),失败重试三遍;这里需要注意如果你的博客开了 CF 5 秒盾或者类似检测,需要调整一下 WAF 规则
- JS 代码:提取<li>里的<a>标签,并且排除掉博客自身的域名:
const html = $input.first().json.data const regex = /<li[^>]*>\s*<a\s+[^>]*href=["']?([^"'\s>]+)["']?[^>]*>/gi; const excludedDomains = ['wuminboke.site']; //排除自己的博客域名 const hrefs = []; let match; while ((match = regex.exec(html)) !== null) { const href = match[1]; const isExcluded = excludedDomains.some(domain => href.includes(domain)); if (!isExcluded) { hrefs.push(href); } } return hrefs.map(href => ({ json: { href } })); - HTTP 请求:逐一发送 GET 请求到 {{ $json.href }} ,并且把设置里的 On Error 改为 Continue (using error output),错误时继续

- 如果:把上一步的 Error 拉到如果,配置 {{ $input.all().length }} # is equal to 0,判断有无错误

- JS 代码:如果上一步“如果”的结果是“否”,那么把错误的网址和错误码拼起来:
const items = $input.all(); const lines = items.map(item => { const href = item.json.href; const status = item.json.error?.status ? ` ${item.json.error.status}` : ''; return `${status}\n ${href}`; }); const message = `检测完成 (共有${lines.length}个错误)\n\n` + lines.join('\n\n'); return [{ json: { message } }]; - TG 推送:利用 TG 机器人发送通知(我在消息前还加了时间,但是不是必要的);在@BotFather 创建机器人获取 Token 并用@userinfobot 获取账号的聊天 ID
不想自己托管 n8n 的可以找找那些免费 Docker 容器服务,比如 ClawCloud 绑定 GitHub 后就有免费的额度可以用 😛
Web hosting by


我一般会选择写个脚本,每次推文章的时候,手动检测下
厉害了,好实用