-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrssparse.go
More file actions
47 lines (39 loc) · 1008 Bytes
/
rssparse.go
File metadata and controls
47 lines (39 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"encoding/xml"
)
//Rss root rss node
type Rss struct {
RssChannel RssChannel `xml:"channel"`
}
//RssChannel channel node
type RssChannel struct {
RssItem []RssItem `xml:"item"`
}
//RssItem item node
type RssItem struct {
Title string `xml:"title"`
Link string `xml:"link"`
LinkEnclosure Enclosure `xml:"enclosure"`
Description string `xml:"description"`
}
//Enclosure rss link enclosure
type Enclosure struct {
URL string `xml:"url,attr"`
Type string `xml:"type,attr"`
Length string `xml:"length,attr"`
}
//EnclosureUrlsFromRssString take
func EnclosureUrlsFromRssString(body string) []Enclosure {
return EnclosureUrlsFromRssBytes([]byte(body))
}
//EnclosureUrlsFromRssBytes scrapes urls from enclosures.
func EnclosureUrlsFromRssBytes(body []byte) []Enclosure {
var rss Rss
xml.Unmarshal(body, &rss)
var result []Enclosure
for _, v := range rss.RssChannel.RssItem {
result = append(result, v.LinkEnclosure)
}
return result
}