Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case "span":
- // Check for the span with class "price"
- hasPriceClass := false
- for _, attr := range token.Attr {
- if attr.Key == "class" && strings.Contains(attr.Val, "price") {
- hasPriceClass = true
- break
- }
- }
- // ...
- if hasPriceClass {
- tokenType = z.Next()
- // Check if the next token is a span with class "amount"
- if tokenType == html.StartTagToken || tokenType == html.SelfClosingTagToken {
- nextToken := z.Token()
- if nextToken.Data == "span" {
- amountClass := false
- for _, attr := range nextToken.Attr {
- if attr.Key == "class" && strings.Contains(attr.Val, "amount") {
- amountClass = true
- break
- }
- }
- // If the next span has class "amount," loop through and print its text content
- if amountClass {
- var currencySymbol, priceValue string
- for {
- tokenType = z.Next()
- if tokenType == html.TextToken {
- currencySymbol = z.Token().Data
- }
- tokenType = z.Next()
- if tokenType == html.TextToken {
- priceValue = z.Token().Data
- } else if tokenType == html.EndTagToken && z.Token().Data == "span" {
- break
- }
- }
- amount := currencySymbol + priceValue
- fmt.Println("Price:", amount)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement