← 返回
未分类

博客监控

博客监控技能 - 监控博客和网站更新,通过RSS或网页变化检测。
博客监控技能:监控博客和网站的更新,支持RSS或网页变化检测。
534422530 534422530 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 307
下载
💾 0
安装
1
版本
#blog#latest#monitor#website

概述

Blog Watcher - 博客监控

> 激活词: 博客监控 / 网站更新 / 追踪博客

安装

pip install feedparser beautifulsoup4 requests

功能

  • RSS订阅监控
  • 网页变化检测
  • 定时检查
  • 通知提醒

Python函数

import feedparser
import hashlib
import requests
from bs4 import BeautifulSoup
from datetime import datetime

class BlogWatcher:
    def __init__(self):
        self.watch_list = []
        self.content_hashes = {}
    
    def add_blog(self, name: str, url: str, use_rss: bool = True):
        self.watch_list.append({
            'name': name,
            'url': url,
            'use_rss': use_rss,
        })
    
    def check_updates(self):
        results = []
        for blog in self.watch_list:
            if blog['use_rss']:
                result = self._check_rss(blog)
            else:
                result = self._check_webpage(blog)
            
            if result:
                results.append(result)
        
        return results
    
    def _check_rss(self, blog: dict) -> dict:
        feed = feedparser.parse(blog['url'])
        if feed.entries:
            latest = feed.entries[0]
            return {
                'name': blog['name'],
                'title': latest.title,
                'link': latest.link,
                'published': latest.get('published', 'Unknown'),
            }
        return None
    
    def _check_webpage(self, blog: dict) -> dict:
        response = requests.get(blog['url'])
        soup = BeautifulSoup(response.text, 'html.parser')
        
        # 获取页面标题
        title = soup.title.string if soup.title else 'No title'
        
        # 计算内容哈希
        content_hash = hashlib.md5(response.text.encode()).hexdigest()
        
        if blog['url'] in self.content_hashes:
            if self.content_hashes[blog['url']] != content_hash:
                self.content_hashes[blog['url']] = content_hash
                return {'name': blog['name'], 'title': title, 'updated': True}
        else:
            self.content_hashes[blog['url']] = content_hash
        
        return None

使用示例

watcher = BlogWatcher()

# 添加博客
watcher.add_blog('技术博客', 'https://blog.example.com/feed.xml')
watcher.add_blog('AI新闻', 'https://news.example.com/rss')

# 检查更新
updates = watcher.check_updates()
for update in updates:
    print(f"[{update['name']}] {update['title']}")

输出格式

## 博客更新

### 检测到 3 个更新

1. **技术博客**
   - 新文章: Python新特性解析
   - 链接: https://blog.example.com/post/123
   - 时间: 2026-04-28

2. **AI新闻**
   - 新文章: GPT-5发布
   - 链接: https://news.example.com/gpt5
   - 时间: 2026-04-28

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-08 00:44 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

it-ops-security

MoltGuard - Security & Antivirus & Guardrails

thomaslwang
MoltGuard — OpenClaw 安全守卫,由 OpenGuardrails 提供。安装后可防止您和您的用户受到提示注入、数据泄露及恶意行为的侵害。
★ 116 📥 31,007
dev-programming

Karpathy编程四大原则

534422530
AI编程四大原则 —— 源自 Karpathy 法则 (forrestchang/andrej-karpathy-skills94.2k⭐)。在AI编程时强制执行四大原则:先思考、保持简单、精准修改、目标驱动。适用于代码审查、代码生成、bu
★ 3 📥 1,029
it-ops-security

OpenClaw Backup

alex3alex
备份与恢复 OpenClaw 数据。适用于创建备份、设置自动备份计划、从备份恢复或管理备份轮转。处理 ~/.openclaw 目录归档并包含适当的排除规则。
★ 90 📥 31,049