Trying to determine if a particular button exists on a page, if the button doesn't exist this code seems to freeze instead of continuing. Any ideas what options there might be to determine if the button exists or not on a page without the code stopping? :)
package main
import (
"log"
"github.com/go-rod/rod"
)
func main() {
urlSlice := []string{
"https://www.amd.com/en/direct-buy/5450881700/us",
"https://www.amd.com/en/direct-buy/5458373400/us",
}
for {
for _, url := range urlSlice {
page := rod.New().MustConnect().MustPage(url)
btn := page.MustElement("#product-details-info > div.container > div > div > div.product-page-description.col-flex-lg-5.col-flex-sm-12 > button")
if btn.MustText() == " ADD TO CART" {
log.Printf(
"%s \t %s",
page.MustInfo().Title,
btn.MustText(),
)
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire