getAttr gets the given attribute from the given node, returning "" if the attribute is not found.
(n *html.Node, attr string)
| 297 | // getAttr gets the given attribute from the given node, returning "" |
| 298 | // if the attribute is not found. |
| 299 | func getAttr(n *html.Node, attr string) string { |
| 300 | res := "" |
| 301 | for _, a := range n.Attr { |
| 302 | if a.Key == attr { |
| 303 | res = a.Val |
| 304 | } |
| 305 | } |
| 306 | return res |
| 307 | } |
| 308 | |
| 309 | // hasAttr returns whether the given node has the given attribute defined. |
| 310 | func hasAttr(n *html.Node, attr string) bool { |