Follow自建RssHub订阅源
Follow⾃建RssHub订阅源
- 准备⼯作
- 添加命名空间
- 创建路由
- 构建docker镜像部署到公⽹
- 准备⼯作
//从github clone 项⽬
git clone https://github.com/DIYgod/RSSHub.git
//安装依赖 npm install
//运⾏
npm run dev
运⾏后

访问浏览器

添加命名空间
⽬录下添加域名作为⽂件夹,如新浪sina
lib/routes
并创建⽂件 来定义命名空间
namespace.ts

创建路由
因为pull的代码就有sina⽂件夹,这⾥创建tousu ⽂件夹作为https://tousu.sina.com.cn/
⿊猫投诉的路由。路由参数说明参考官⽹:https://docs.rsshub.app/zh/joinus/new-
按照路由结构创建路由
import { Route } from '@/types';
export const route: Route = { path: '/tousu',
name: '⿊猫投诉',
url: 'tousu.sina.com.cn', example:'/sina/tousu', maintainers:['JianLinWei1'],
radar: [
{
source: ['tousu.sina.com.cn'],
},
],
handler,
}
async function handler(ctx){
return {
title: '⿊猫投诉-⾸⻚最热投诉',
link: 'https://tousu.sina.com.cn/',
//item: out,
};
}
请求http://localhost:1200/api/radar/rules 可以看到添加的路由

调试
在代码中添加debugger关键字


在chrome调试模式下点击 node.js devtools
因API有签名算法,换成puppeteer 完整代码如下
import { Route } from '@/types'; import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
import logger from '@/utils/logger'; import puppeteer from '@/utils/puppeteer'; import { load } from 'cheerio';
export const route: Route = { path: '/tousu',
name: '⿊猫投诉',
url: 'tousu.sina.com.cn', example: '/sina/tousu', maintainers: ['JianLinWei1'], radar: [
{
source: ['tousu.sina.com.cn'],
},
],
handler,
}
async function handler(ctx) {
// 导⼊ puppeteer ⼯具类并初始化浏览器实例
const browser = await puppeteer();
// 打开⼀个新标签⻚
const page
=
// 访问⽬标链接
const link
=
await browser.newPage(); 'https://tousu.sina.cn';
// ofetch 请求会被⾃动记录,
// 但 puppeteer 请求不会
// 所以我们需要⼿动记录它们
logger.http(`Requesting ${link}`); await page.goto(link, {
// 指定⻚⾯等待载⼊的时间
waitUntil: 'networkidle2',
});
// 获取⻚⾯的 HTML 内容
=
const response
// 关闭标签⻚
page.close();
await page.content();
const $ load(response);
=
const blackcatCons = $('div.blackcat-con').toArray(); const items = blackcatCons.map((item) => {
const title const link
=
$(item).find('h1.blackcat-hot').text()
$(item).find('a.box').attr('href')
=
const description = $(item).find('p').text() $(item).
+
const date $(item).find('span.time').text()
=
const author = $(item).find('span.name').text() return {
title: title,
// ⽂章链接
link: link,
// ⽂章正⽂
description: description,
// ⽂章发布⽇期
// pubDate: date,
// 如果有的话,⽂章作者
author: author,
}
})
return {
// 源标题
title: `⿊猫投诉-新浪旗下消费者服务平台`,
// 源链接
link: `https://tousu.sina.cn`,
// 源⽂章
item: items,
};
}
浏览器打开http://IP:1200/sina/tousu 就可以看到内容

浏览器插件https://github.com/DIYgod/RSSHub-Radar可以预览


- 构建docker镜像部署到公⽹
RssHub项⽬中已经有Dockerfile ⽂件,直接执⾏构建命令
docker build -t myrsshub:1.0.1 .
构建完后 我是将镜像推送到阿⾥个⼈仓库

使⽤docker-compose部署,将镜像改为⾃⼰的私有镜像。


运⾏成功后可远程访问路由,使⽤Follow可预览订阅

浙公网安备 33010602011771号