Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //..
- initialize a list
- var list[]*html.Node
- // Define a function to traverse the HTML document
- var processPokemon func(*html.Node)
- processPokemon = func(n *html.Node) {
- // Check for all <li> elements with class "product"
- if n.Type == html.ElementNode && n.Data == "li" {
- for _, attr := range n.Attr {
- if attr.Key == "class" && strings.Contains(attr.Val, "product") {
- liList = append(liList, n)
- }
- }
- }
- // Traverse child nodes
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- processPokemon(c)
- }
- }
- // Call the function to start processing the Pokémon details
- processPokemon(doc)
- // Process the details of the first <li> element from the list
- processPokemonDetails(list[0])
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement