爬取京东商品信息的实例 —— Golang

安装

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

相关文章
相关标签/搜索