Go Rod If 按钮

时间:2021-08-02 00:57:22

标签: go if-statement button element

尝试确定页面上是否存在特定按钮,如果该按钮不存在,此代码似乎冻结而不是继续。任何想法可能有哪些选项可以确定按钮是否存在于页面上而不停止代码? :)

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(),
                )

            }

        }
    }
}

0 个答案:

没有答案