rules

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Kaola = &spider.Spider{
	Name:        "考拉海淘",
	Description: "考拉海淘商品数据 [Auto Page] [www.kaola.com]",

	EnableCookie: false,
	RuleTree: &spider.RuleTree{
		Root: func(ctx *spider.Context) {
			ctx.AddQueue(&request.Request{URL: "http://www.kaola.com", Rule: "获取版块URL"})
		},

		Trunk: map[string]*spider.Rule{

			"获取版块URL": {
				ParseFunc: func(ctx *spider.Context) {
					query := ctx.GetDom()
					lis := query.Find("#funcTab li a")
					lis.Each(func(i int, s *goquery.Selection) {
						if i == 0 {
							return
						}
						if url := s.Attr("href"); url.IsSome() {
							ctx.AddQueue(&request.Request{URL: url.Unwrap(), Rule: "商品列表", Temp: map[string]interface{}{"goodsType": s.Text()}})
						}
					})
				},
			},

			"商品列表": {
				ParseFunc: func(ctx *spider.Context) {
					query := ctx.GetDom()
					query.Find(".proinfo").Each(func(i int, s *goquery.Selection) {
						if url := s.Find("a").Attr("href"); url.IsSome() {
							ctx.AddQueue(&request.Request{
								URL:  "http://www.kaola.com" + url.Unwrap(),
								Rule: "商品详情",
								Temp: map[string]interface{}{"goodsType": ctx.GetTemp("goodsType", "").(string)},
							})
						}
					})
				},
			},

			"商品详情": {

				ItemFields: []string{
					"标题",
					"价格",
					"品牌",
					"采购地",
					"评论数",
					"类别",
				},
				ParseFunc: func(ctx *spider.Context) {
					query := ctx.GetDom()

					title := query.Find(".product-title").Text()

					price := query.Find("#js_currentPrice span").Text()

					brand := query.Find(".goods_parameter li").Eq(0).Text()

					from := query.Find(".goods_parameter li").Eq(1).Text()

					discussNum := query.Find("#commentCounts").Text()

					ctx.Output(map[int]interface{}{
						0: title,
						1: price,
						2: brand,
						3: from,
						4: discussNum,
						5: ctx.GetTemp("goodsType", ""),
					})
				},
			},
		},
	},
}

Kaola Haitao - overseas direct purchase, 7-day no-reason return, worry-free after-sales

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL