1.安裝 jd-spidergit
$ go get github.com/matchseller/jd-spider
2.在你的項目中導入包:github
import ( "github.com/matchseller/jd-spider/category" "github.com/matchseller/jd-spider/price" "github.com/matchseller/jd-spider/product" )
1.抓取商品目錄app
func main(){ categoryUrls, err := category.Crawl() }
2.抓取商品信息ide
func main(){ categoryUrls, err := category.Crawl() if err == nil { products, _ := product.Crawl(categoryUrls[:10]) } }
3.抓取價格code
func main(){ categoryUrls, err := category.Crawl() if err == nil { products, _ := product.Crawl(categoryUrls[:10]) var skuIds []string for _, v := range products{ skuIds = append(skuIds, v.SkuId) } jPrices := price.Crawl(&skuIds) } }
項目在Github上,歡迎給Starget