站点图标 谷姐靓号网

写个了网页关键词检测,从此传家宝不再错过-toot

Rate this post

    addEventListener("scheduled", event => {
    event.waitUntil(checkKeywordsAndNotify());
    });

    async function checkKeywordsAndNotify() {
    const url = 'https://hostloc.com';// 要检测的网页URL
    const keyword = '全球主机交流';// 要检测的关键词
    const telegramToken = '##';// TG机器人Token
    const chatId = '##';//要推送的TG用户ID

    try {
    const urlWithTimestamp = `${url}?t=${Date.now()}`;

    const response = await fetch(urlWithTimestamp, {
    method: 'GET',
    headers: {
    'Cache-Control': 'no-cache',
    'Pragma': 'no-cache'
    }
    });
    const text = await response.text();

    if (!text.includes(keyword)) {
    await sendTelegramNotification(telegramToken, chatId, `关键词 "${keyword}" 已从 ${url} 上消失`);
    }
    } catch (error) {
    await sendTelegramNotification(telegramToken, chatId, `获取或处理URL时出错: ${error.message}`);
    }
    }

    async function sendTelegramNotification(token, chatId, message) {
    const telegramUrl = `https://api.telegram.org/bot${token}/sendMessage`;
    const response = await fetch(telegramUrl, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
    chat_id: chatId,
    text: message
    })
    });
    return response.json();
    }

1,无需服务器,丢进cloudflare的workers
2,设定→触发程序→Cron

可以检测传家宝是否补货,也可以检测自己的网站是不是掉线了

热议
2楼 燕十三丶 昨天20:55

很多机器人可以直接检测啊 就是关键字不好搞

3楼 toot 昨天20:58

有个缺点,一旦传家宝补货了,机器人会一直提醒你。数据库可以解决这个问题,但是想法就是简单稳定快捷。数据库增加了不确定因素

4楼 toot 昨天21:01

很多机器人可以直接检测啊 就是关键字不好搞

别人的能跟自己建的比啊

5楼 平安喜乐 昨天22:21

https://github.com/Xinslive/NotifyMe

6楼 xwcolmidad 昨天22:22

https://github.com/Xinslive/NotifyMe

这个不错 简单实用

7楼 平安喜乐 昨天22:22

分享一下我的网页关键词检测开源项目

9楼 陶泥猴子 昨天22:29

要是能自动下单就好了

申明:本文内容由网友收集分享,仅供学习参考使用。如文中内容侵犯到您的利益,请在文章下方留言,本站会第一时间进行处理。

退出移动版