-
Notifications
You must be signed in to change notification settings - Fork 0
/
html_parser.go
39 lines (35 loc) · 1.12 KB
/
html_parser.go
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
package bslc
import "code.google.com/p/go.net/html"
func parseHTML(content *Content, container URLContainer) {
doc, err := html.Parse(content.Reader())
if err != nil {
return
}
var parse func(*html.Node)
parse = func(n *html.Node) {
if n.Type == html.ElementNode {
switch n.Data {
case "a", "link":
for _, attr := range n.Attr {
if attr.Key == "href" {
if path := attr.Val; isValidPath(path) {
container.AddURL(completeURL(content.URL.String(), path))
}
break
}
}
case "embed", "input", "img", "script", "source":
for _, attr := range n.Attr {
if attr.Key == "src" {
container.AddURL(completeURL(content.URL.String(), attr.Val))
break
}
}
}
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
parse(c)
}
}
parse(doc)
}