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