安装

1.安装 jd-spider

$ go get github.com/matchseller/jd-spider

2.在你的项目中导入包:

import (
    "github.com/matchseller/jd-spider/category"
    "github.com/matchseller/jd-spider/price"
    "github.com/matchseller/jd-spider/product"
)

用法

1.抓取商品目录

func main(){
    categoryUrls, err := category.Crawl()
}

2.抓取商品信息

func main(){
    categoryUrls, err := category.Crawl()
    if err == nil {
        products, _ := product.Crawl(categoryUrls[:10])
    }
}

3.抓取价格

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上,欢迎给Star