Advertisement
dereksir

Untitled

Dec 29th, 2023
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.46 KB | None | 0 0
  1. func main() {
  2.     //..
  3.  
  4.     // find all <li> elements
  5.     var processAllPokemon func(*html.Node)
  6.     processAllPokemon = func(n *html.Node) {
  7.         if n.Type == html.ElementNode && n.Data == "li" {
  8.             // process the Pokemon details within each <li> element
  9.             processNode(n)
  10.  
  11.         }
  12.         // traverse the child nodes
  13.         for c := n.FirstChild; c != nil; c = c.NextSibling {
  14.             processAllPokemon(c)
  15.         }
  16.     }
  17.     // make a recursive call to your function
  18.     processAllPokemon(doc)
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement