From bcc0bd0c3a948e1fb43aa593e90b56f5bba4ea80 Mon Sep 17 00:00:00 2001 From: 3377 <35794406@qq.com> Date: Fri, 10 Jan 2025 13:30:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(internal/rss):=20=E7=AE=80=E5=8C=96=20?= =?UTF-8?q?HTTP=20=E8=AF=B7=E6=B1=82=E5=A4=B4=E8=AE=BE=E7=BD=AE=E5=B9=B6?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=9C=AA=E4=BD=BF=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了随机用户代理函数和特定网站的请求头设置 - 添加了通用的浏览器标识和必要的头信息 - 删除了未使用的导入和初始化代码 - 简化了版本号 --- internal/rss/rss.go | 43 ++++++------------------------------------- version | 2 +- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/internal/rss/rss.go b/internal/rss/rss.go index 5d663ba..3dcf3a5 100644 --- a/internal/rss/rss.go +++ b/internal/rss/rss.go @@ -2,28 +2,15 @@ package rss import ( "log" - "math/rand" "net/http" "strings" "sync" "time" - "fmt" "github.com/mmcdole/gofeed" "rss2telegram/internal/storage" ) -var userAgents = []string{ - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edge/120.0.0.0 Safari/537.36", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0", - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15", -} - -func getRandomUserAgent() string { - return userAgents[rand.Intn(len(userAgents))] -} - type MessageHandler func(title, url, group string, pubDate time.Time, matchedKeywords []string) error type Manager struct { @@ -126,25 +113,12 @@ func (m *Manager) checkFeed(feed *Feed) { return } - // 根据不同的域名使用不同的请求头 - if strings.Contains(feed.URL, "hostloc.com") { - // hostloc 特定的请求头 - req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36") - req.Header.Set("Accept", "application/rss+xml,application/xml;q=0.9") - req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8") - req.Header.Set("Referer", "https://hostloc.com/forum.php") - } else if strings.Contains(feed.URL, "nodeseek.com") { - // nodeseek 特定的请求头 - req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36") - req.Header.Set("Accept", "application/xml,application/rss+xml;q=0.9") - req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9") - req.Header.Set("Referer", "https://nodeseek.com/") - } else { - // 其他网站使用通用请求头 - req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36") - req.Header.Set("Accept", "application/rss+xml,application/xml;q=0.9,*/*;q=0.8") - req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8") - } + // 添加浏览器标识和其他必要的头信息 + req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36") + req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") + req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8") + req.Header.Set("Connection", "keep-alive") + req.Header.Set("Upgrade-Insecure-Requests", "1") // 使用自定义客户端解析 Feed fp.Client = client @@ -187,8 +161,3 @@ func (m *Manager) matchKeywords(item *gofeed.Item, keywords []string) []string { return matched } - -func init() { - // 初始化随机数生成器 - rand.Seed(time.Now().UnixNano()) -} diff --git a/version b/version index 6c8bbe7..f6bb848 100644 --- a/version +++ b/version @@ -1,2 +1,2 @@ -3.0-25.01.10.2 +3.0-25.01.10