Advertisement
dereksir

Untitled

Dec 20th, 2023 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.38 KB | None | 0 0
  1.             case "span":
  2.                 // Check for the span with class "price"
  3.                 hasPriceClass := false
  4.                 for _, attr := range token.Attr {
  5.                     if attr.Key == "class" && strings.Contains(attr.Val, "price") {
  6.                         hasPriceClass = true
  7.                         break
  8.                     }
  9.                 }
  10.  
  11.                 // ...
  12.  
  13.                 if hasPriceClass {
  14.                     tokenType = z.Next()
  15.  
  16.                     // Check if the next token is a span with class "amount"
  17.                     if tokenType == html.StartTagToken || tokenType == html.SelfClosingTagToken {
  18.                         nextToken := z.Token()
  19.                         if nextToken.Data == "span" {
  20.                             amountClass := false
  21.                             for _, attr := range nextToken.Attr {
  22.                                 if attr.Key == "class" && strings.Contains(attr.Val, "amount") {
  23.                                     amountClass = true
  24.                                     break
  25.                                 }
  26.                             }
  27.  
  28.                             // If the next span has class "amount," loop through and print its text content
  29.                             if amountClass {
  30.                                 var currencySymbol, priceValue string
  31.  
  32.                                 for {
  33.                                     tokenType = z.Next()
  34.                                     if tokenType == html.TextToken {
  35.                                         currencySymbol = z.Token().Data
  36.                                     }
  37.  
  38.                                     tokenType = z.Next()
  39.                                     if tokenType == html.TextToken {
  40.                                         priceValue = z.Token().Data
  41.                                     } else if tokenType == html.EndTagToken && z.Token().Data == "span" {
  42.                                         break
  43.                                     }
  44.                                 }
  45.  
  46.                                 amount := currencySymbol + priceValue
  47.                                 fmt.Println("Price:", amount)
  48.                             }
  49.                         }
  50.                     }
  51.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement