部署changedetection.io,一个网站更改检测、监控和通知的开源工具

部署changedetection.io,一个网站更改检测、监控和通知的开源工具

admin
2024-07-30 / 0 评论 / 67 阅读 / 正在检测是否收录...

官方Github: https://github.com/dgtlmoon/changedetection.io

Web Site Change Detection, Monitoring and Notification.
Live your data-life pro-actively, Detect website changes and perform meaningful actions, trigger notifications via Discord, Email, Slack, Telegram, API calls and many more.

网站更改检测、监控和通知。
主动体验您的数据生活,检测网站更改并执行有意义的操作,通过 Discord、电子邮件、Slack、电报、API 调用等触发通知。

image.png

准备工作

Docker 安装教程 (菜鸟教程):网页链接

Docker-Compose 安装教程 (菜鸟教程):网页链接

宝塔面板,反代环境

部署

执行以下命令,新建目录

mkdir -p /opt/docker/changedetection.io && cd /opt/docker/changedetection.io

新建docker-compose.yaml文件

然后输入以下配置内容:

version: "3"
services:
  changedetection:
    image: ghcr.io/dgtlmoon/changedetection.io
    container_name: changedetection
    hostname: changedetection
    restart: unless-stopped
    environment:
      - USE_X_SETTINGS=1
      - BASE_URL=https:// #修改成你的域名
      - PLAYWRIGHT_DRIVER_URL=ws://playwright-chrome:3000/
    ports:
      - 20041:5000 #2077为暴露端口,如被占用,请自行更改替换,需要在云服务器的控制台防火墙开放相应端口!
    volumes:
      - changedetection-data:/datastore

  playwright-chrome:
    image: browserless/chrome
    hostname: playwright-chrome
    restart: unless-stopped

volumes:
  changedetection-data:

输入执行以下命令后台启动容器

docker compose up -d

访问 https://ip:20041 进入主页

修改网页抓取方式

点击SETTINGSFetching中的Fetch Method,将其改为Playwright Chromium/Javascript via 'ws://playwright-chrome:3000/',然后Save即可!

监控

image.png

可以改监控间隔,点击 Edit:

image.png

General:
  URL: https://api.bilibili.com/x/space/wbi/arc/search?mid=8366990&ps=30&tid=0&pn=1&keyword=&order=pubdate&order_avoided=true&w_rid=b37f7220280dbec445b877940e8bbc36&wts=1671982474
  Time Between Check: 0 0 0 5 0

Request:
  Fetch Method: Basic fast Plaintext/HTTP Client
  Request method: GET
  Request headers: {
    accept: application/json, text/plain, */*
    accept-encoding: gzip, deflate, br
    accept-language: zh-CN,zh;q=0.9,en-AS;q=0.8,en;q=0.7
    cache-control: no-cache
    cookie: buvid3=F8D5D1C8-55E2-23AC-AA4B-CD66147A8A0488878infoc; i-wanna-go-back=-1; b_ut=7;    _uuid=938E2C3F-2567-F173-BA77-8E34C109BC47888980infoc; buvid_fp=a65c806ec103b5691068a7fe2d31f818;   buvid4=891AB099-8FE4-6031-3245-4DCA36CEBFD789604-022051401-sluv7aFmF1Lh17bDnV1PEA%3D%3D; CURRENT_FNVAL=4048;     blackside_state=1; PVID=5; b_lsid=F10E97E10F_18549E99616
    dnt: 1
    origin: https://space.bilibili.com
    pragma: no-cache
    referer: https://space.bilibili.com/8366990/video
    sec-ch-ua: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"
    sec-ch-ua-mobile: ?0
    sec-ch-ua-platform: "macOS"
    sec-fetch-dest: empty
    sec-fetch-mode: cors
    sec-fetch-site: same-site
    user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
  }

Filters & Triggers:
  CSS/JSONPath/JQ/XPath Filters: json:$.data.list.vlist[0].[title]
  Notifications: tgram://5705562690:AAasdasddbaInDL0lHh8bcab-A7O4BpWv9_gvfE/2053317177/

最新案例:

想象一下,你想添加你最喜欢的网站 Opensource.com 进行监控。你只想知道主要标注文章何时包含 “python” 一词,并且通过 Matrix 收到通知。

要做到这点,首先要使用“视觉选择器Visual Filter Selector”工具。(这需要连接 playwright 浏览器界面)。
image.png
该工具会自动计算出针对内容的最佳 Xpath 或 CSS 过滤器。否则,你会从每天的页面更新中得到大量的噪音。

接下来,访问“Filters & Triggers”标签。
image.png
在 “CSS/JSON/XPATH Filter”区域(蓝色圆圈),你可以看到上一步自动生成的 CSS 过滤器。

有几个有用的过滤器,比如“Remove elements”(适合移除嘈杂的元素)、“忽略文本Ignore text”、“触发/等待文本Trigger/wait for text”,和“如果文本匹配则阻止变化检测Block change-detection if text matches”(用于等待一些文本消失,如“售罄”)。

在“触发/等待文本Trigger/wait for text”(红色圆圈)中,输入你想监测的关键词。(在这个例子中是 “python”)。

最后一步是在“通知Notifications”选项卡中,你要在那里配置你想收到的通知。下面我使用邮箱、telegram添加了一个 通知目标。

JSON API 监控案例

找一个天气预报的 JSON API,请求是restfull 风格,city_code 为 9 位数字。只要拼接在地址 “http://t.weather.itboy.net/api/weather/city/+city_code” 后面即可。

city_code 可以在这里查询: https://github.com/baichengzhou/weather.api/blob/master/src/main/resources/citycode-2019-08-23.json

比如上海的 city_code 为 101020100
image.png
所以在浏览器中输入 http://t.weather.itboy.net/api/weather/city/101020100 就能看到上海的天气信息
image.png

将网页上的文本全部复制(Ctrl+A 然后 Ctrl+C),接着打开网页:https://jsonpath.com

这个网址可用于 JSON 的语法测试

将前面复制的内容粘贴到左侧的 Inputs,因为希望返回所有的数据,所以在 JSONPath Syntax 中输入了 $
image.png
右侧的 Evaluation Results 不仅返回了所有的数据,并且对 JSON 数据进行了格式化处理,更易于阅读

如果只是需要获取温度,可以在 JSONPath Syntax 中输入 $.data.wendu

image.png
准备工作到这里就差不多了,返回到 Changedetection 新增一个监控,分别填入下面的内容后,点 Watch

  • 网址:http://t.weather.itboy.net/api/weather/city/101020100
  • tag:天气

image.png

image.png
在 CSS/JSON Filter 中输入 json:$.data.wendu,其中前缀 json: 是必须要的
image.png

通知

邮箱推送

点右上角的 SETTINGS 是 default global settings,只需要在 Notification URL List 中设置通知方式

Changedetection 采用了 apprise 项目来实现 通知 功能,可惜除了 邮件 ,老苏没找到手机上已经安装的应用

所有支持的通知方式都在这里:https://github.com/caronc/apprise

邮件发送的 URL 地址是

0

评论

博主关闭了所有页面的评论