From 3a8d85684c49b66fa4e1747613a0a6f46d1ca8d1 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 15 Mar 2025 14:53:14 +0800 Subject: [PATCH] :lipstick: Optimize scraper thumbnail logic --- pkg/internal/services/scraper.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/internal/services/scraper.go b/pkg/internal/services/scraper.go index 5414aa1..a3686fb 100644 --- a/pkg/internal/services/scraper.go +++ b/pkg/internal/services/scraper.go @@ -249,7 +249,11 @@ func ScrapNews(target string, parent ...models.NewsArticle) (*models.NewsArticle }) c.OnHTML("article img", func(e *colly.HTMLElement) { if len(article.Thumbnail) == 0 { - article.Thumbnail = e.Attr("src") + url := e.Attr("src") + // Usually, if the image have a relative path, it is some static assets instead of content. + if strings.HasPrefix(url, "http") { + article.Thumbnail = url + } } })