mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Add readability package to fetch original content
This commit is contained in:
parent
b75a9987ba
commit
7a35c58f53
17 changed files with 545 additions and 70 deletions
38
reader/scraper/scraper.go
Normal file
38
reader/scraper/scraper.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package scraper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/miniflux/miniflux2/http"
|
||||
"github.com/miniflux/miniflux2/reader/readability"
|
||||
"github.com/miniflux/miniflux2/reader/sanitizer"
|
||||
)
|
||||
|
||||
// Fetch download a web page a returns relevant contents.
|
||||
func Fetch(websiteURL string) (string, error) {
|
||||
client := http.NewClient(websiteURL)
|
||||
response, err := client.Get()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if response.HasServerFailure() {
|
||||
return "", errors.New("unable to download web page")
|
||||
}
|
||||
|
||||
page, err := response.NormalizeBodyEncoding()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
content, err := readability.ExtractContent(page)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return sanitizer.Sanitize(websiteURL, content), nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue