Golang Colly Scraping - 网站验证码抓取我的数据

Golang Colly Scraping - Website Captcha Catches My Scrape

我确实为亚马逊产品标题做了抓取,但亚马逊验证码捕获了我的抓取器。我尝试了 10 次-去 运行 main.go(8 次抓住了我 - 2 次我 抓取了 产品标题)

我研究了这个但是我没有找到任何 golang 的解决方案(只有 python)有什么解决方案适合我吗?


package main

import (
    "fmt"
    "strings"0

    "github.com/gocolly/colly"
)

func main() {

    // Create a Collector specifically for Shopify
    c := colly.NewCollector(
        colly.AllowedDomains("www.amazon.com", "amazon.com"),
    )
    c.OnHTML("div", func(h *colly.HTMLElement) {
        capctha := h.Text
        title := h.ChildText("span#productTitle")
        fmt.Println(strings.TrimSpace(title))
        fmt.Println(strings.TrimSpace(capctha))
    })

    // Start the collector
    c.Visit("https://www.amazon.com/Bluetooth-Over-Ear-Headphones-Foldable-Prolonged/dp/B07K5214NZ")
}

Output:

Enter the characters you see below Sorry, we just need to make sure you're not a robot. For best results, please make sure your browser is accepting cookies.

如果你不介意不同的包,我写了一个包来搜索HTML (本质上是github.com/tdewolff/parse周围的薄包装):

package main

import (
   "github.com/89z/parse/html"
   "net/http"
   "os"
)

func main() {
   req, err := http.NewRequest(
      "GET", "https://www.amazon.com/dp/B07K5214NZ", nil,
   )
   req.Header = http.Header{
      "User-Agent": {"Mozilla"},
   }
   res, err := new(http.Transport).RoundTrip(req)
   if err != nil {
      panic(err)
   }
   defer res.Body.Close()
   lex := html.NewLexer(res.Body)
   lex.NextAttr("id", "productTitle")
   os.Stdout.Write(lex.Bytes())
}

结果:

Bluetooth Headphones Over-Ear, Zihnic Foldable Wireless and Wired Stereo
Headset Micro SD/TF, FM for Cell Phone,PC,Soft Earmuffs &Light Weight for
Prolonged Waring(Rose Gold)

https://github.com/89z/parse