Skip to content

Commit

Permalink
Add publish date time
Browse files Browse the repository at this point in the history
  • Loading branch information
chunvv committed Apr 6, 2021
1 parent dd58be2 commit 035c860
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions goscraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package goscraper
import (
"bytes"
"fmt"
"golang.org/x/net/html"
"golang.org/x/net/html/charset"
"io"
"net/http"
"net/url"
"regexp"
"strings"

"golang.org/x/net/html"
"golang.org/x/net/html/charset"
)

var (
Expand All @@ -30,12 +29,13 @@ type Document struct {
}

type DocumentPreview struct {
Icon string
Name string
Title string
Description string
Images []string
Link string
Icon string
Name string
Title string
Description string
Images []string
Link string
PublishedTime string
}

func Scrape(uri string, maxRedirect int) (*Document, error) {
Expand Down Expand Up @@ -231,6 +231,8 @@ func (scraper *Scraper) parseDocument(doc *Document) error {
}
}
switch cleanStr(property) {
case "og:article:published_time", "article:published_time":
doc.Preview.PublishedTime = content
case "og:site_name":
doc.Preview.Name = content
case "og:title":
Expand All @@ -257,7 +259,6 @@ func (scraper *Scraper) parseDocument(doc *Document) error {
}

doc.Preview.Images = []string{ogImgUrl.String()}

}

case "title":
Expand Down

0 comments on commit 035c860

Please sign in to comment.