Advertisement
dereksir

Untitled

Dec 21st, 2023 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.73 KB | None | 0 0
  1. //..   
  2.     initialize a list
  3.     var list[]*html.Node
  4.     // Define a function to traverse the HTML document
  5.     var processPokemon func(*html.Node)
  6.     processPokemon = func(n *html.Node) {
  7.         // Check for all <li> elements with class "product"
  8.         if n.Type == html.ElementNode && n.Data == "li" {
  9.             for _, attr := range n.Attr {
  10.                 if attr.Key == "class" && strings.Contains(attr.Val, "product") {
  11.                     liList = append(liList, n)
  12.                 }
  13.             }
  14.         }
  15.  
  16.         // Traverse child nodes
  17.         for c := n.FirstChild; c != nil; c = c.NextSibling {
  18.             processPokemon(c)
  19.         }
  20.     }
  21.  
  22.     // Call the function to start processing the Pokémon details
  23.     processPokemon(doc)
  24.  
  25.     // Process the details of the first <li> element from the list
  26.     processPokemonDetails(list[0])
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement