package main

import (
"fmt"
"log"
"strings"

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

func main() {
const src = `
<body>
<noscript>message</noscript>
<img src="img4.png" alt="4" />
<img src="img2.png" alt="2" />
<img src="img3.png" alt="3" />
</body>
`

doc, err := html.Parse(strings.NewReader(src))
if err != nil {
log.Fatal(err)
}
var f func(*html.Node)
f = func(n *html.Node) {
if n.Type == html.ElementNode && n.Data == "img" {
for _, a := range n.Attr {
if a.Key == "alt" {
fmt.Printf("a.Key=%q a.Val=%q\n", a.Key, a.Val)
break
}
}
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
f(c)
}
}
f(doc)
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to