service

package
v0.0.0-...-6ef2de5 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Colly

type Colly struct {
	C       *colly.Collector
	Cdetail *colly.Collector

	WriteNum     int //写入次数
	WriteChannle chan map[string]string
	// contains filtered or unexported fields
}

func (*Colly) BuildC

func (co *Colly) BuildC(Url string)

初始化建立colly实例

func (*Colly) GetContent

func (co *Colly) GetContent(Rule Rule)

根据规则抓取数据

func (*Colly) GetDContent

func (co *Colly) GetDContent(Name string, Rule Rule, SubRule []SubRule)

根据规则抓取数据

func (*Colly) GetPageContent

func (co *Colly) GetPageContent(Rule PageRule)

根据规则提取分页数据

type PageRule

type PageRule struct {
	Type  int    `json:"type"`  //采集规则 0 不采集分页  1 html 2接口数据
	Page  int    `json:"page"`  //采集第几页 0为采集全部
	Num   int    `json:"num"`   //总共采集几页 0为无限制
	Match string `json:"match"` //分页提取规则 type为1:则输入jquery提取分页按钮  2:输入分页连接其中 分页处用{page}替换
}

分页规则

type Rule

type Rule struct {
	Type     int       `json:"type"`     //采集规则  1 html 2接口数据
	Name     string    `json:"name"`     //规则名称
	Field    string    `json:"field"`    //规则映射的字段名称
	Match    string    `json:"match"`    //type=2  则为正则表达式前缀,type=1 html 则为jquery selector规则
	PageRule PageRule  `json:"pagerule"` //分页规则
	SubMatch string    `json:"submatch"` //内容规则 jquery selector
	SubRule  []SubRule `json:"subrules"` //内容详细内容
}

规则结构

type Spider

type Spider struct {
	Co Colly
}

func (*Spider) GetUrlconfig

func (s *Spider) GetUrlconfig(name string) (UrlConfig, error)

func (*Spider) NormalRun

func (s *Spider) NormalRun(name string)

通用爬虫启动

func (*Spider) ScanAll

func (s *Spider) ScanAll() ([]Urls, error)

扫描全部规则文件

func (*Spider) SpiderRun

func (s *Spider) SpiderRun(name string)

根据名称参数启动爬虫

type SubRule

type SubRule struct {
	Type  int    `json:"type"`  //采集规则  1 html 2接口数据
	Name  string `json:"name"`  //规则名称
	Field string `json:"field"` //规则映射的字段名称
	Match string `json:"match"` //type=2  则为正则表达式前缀,type=1 html 则为jquery selector规则
}

type UrlConfig

type UrlConfig struct {
	Name   string `json:"name"`   //配置名称
	Tbname string `json:"tbname"` //对应表名
	Url    string `json:"url"`    //url
	Rules  []Rule `json:"rules"`  //规则
	Out    int    `json:"out"`    //选择输出方式 1 csv 2 mysql
}

定义每个url的配置结构

type Urls

type Urls struct {
	Name string
	Url  string
}

url

Jump to

Keyboard shortcuts

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