form

package
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func If

func If(condition bool, trueVal, falseVal interface{}) interface{}

If 伪三元运算

Types

type CustomForm added in v2.0.1

type CustomForm struct {
	Host                       string                              //网站域名
	Channel                    string                              //栏目链接,页码用[PAGE]替换
	PageStart                  int                                 //页码起始页
	Length                     int                                 //爬取页码长度
	ListSelector               string                              //列表选择器
	HrefSelector               string                              //a链接选择器,相对于列表选择器
	DisableAutoCoding          bool                                //是否自动转码
	LazyImageAttrName          string                              //懒加载图片属性,默认为data-original
	DisableImageExtensionCheck bool                                //禁用图片拓展名检查,禁用后所有图片拓展名强制为png
	AllowImageExtension        []string                            //允许下载的图片拓展名
	DefaultImg                 func(form *Form, item Field) string //图片出错时,设置默认图片
	DetailFields               map[string]Field                    //详情页面字段选择器
	ListFields                 map[string]Field                    //列表页面字段选择器,暂不支持api爬取
	CustomExcelHeader          bool                                //自定义Excel表格头部
	DetailCoroutineNumber      int                                 //爬取详情页协程数
	HttpTimeout                time.Duration                       //请求超时时间
	HttpHeader                 map[string]string                   //header
	MiddleHrefSelector         []string                            //中间层a链接选择器,当详情页有多层时使用
}

type Field

type Field struct {
	Types        fileTypes.FieldTypes
	Selector     string                               //字段选择器
	AttrKey      string                               //属性值参数
	ImagePrefix  func(form *Form, path string) string //图片路径前缀,会添加到图片路径前缀,但不会生成文件夹
	ImageDir     string                               //图片子文件夹,支持变量 1.[date:Y-m-d] 2.[random:1-100] 3.[singleField:title]
	ExcelHeader  string                               //excel表头,需要CustomExcelHeader为true,例:A
	RegularIndex int                                  //正则匹配中的反向引用的下标,默认是1
}

type Form

type Form struct {
	Host                       string          //网站域名
	Channel                    string          //栏目链接,页码用[PAGE]替换
	PageStart                  int             //页码起始页
	Length                     int             //爬取页码长度
	Client                     *request.Client //http客户端
	ListSelector               string          //列表选择器
	HrefSelector               string          //a链接选择器,相对于列表选择器
	Mode                       mode.Mode
	DisableAutoCoding          bool //是否自动转码
	Notice                     *notice.Notice
	Wait                       sync.WaitGroup
	LazyImageAttrName          string                              //懒加载图片属性,默认为data-original
	DisableImageExtensionCheck bool                                //禁用图片拓展名检查,禁用后所有图片拓展名强制为png
	AllowImageExtension        []string                            //允许下载的图片拓展名
	DefaultImg                 func(form *Form, item Field) string //图片出错时,设置默认图片
	DetailFields               map[string]Field                    //详情页面字段选择器
	ListFields                 map[string]Field                    //列表页面字段选择器,暂不支持api爬取
	Storage                    chan map[string]string              //数据结果通道
	CustomExcelHeader          bool                                //自定义Excel表格头部
	DetailCoroutineNumber      int                                 //爬取详情页协程数
	DetailCoroutineChan        chan bool                           //限制详情页并发chan
	DetailWait                 sync.WaitGroup
	HttpTimeout                time.Duration     //请求超时时间
	HttpHeader                 map[string]string //header
	DetailSize                 int               //每个列表的详情数量
	Total                      int               //预计爬取总数
	CurrentIndex               int               //当前爬取数量
	MiddleSelector             []string          //中间层选择器,当详情页有多层时使用
}

func (*Form) DealCoding

func (f *Form) DealCoding(html string, header http2.Header) (string, error)

DealCoding 解决编码问题

func (*Form) DownImg

func (f *Form) DownImg(url string, item Field, res *sync.Map) string

DownImg 下载图片(包括生成文件夹)

func (*Form) GetCharsetByContentType

func (f *Form) GetCharsetByContentType(contentType string) string

GetCharsetByContentType 从contentType中获取编码

func (*Form) GetDir

func (f *Form) GetDir(path string, res *sync.Map) string

func (*Form) GetHref

func (f *Form) GetHref(href string) string

GetHref 获取完整a链接

func (*Form) GetHtml added in v2.0.6

func (f *Form) GetHtml(url string) (string, error)

GetHtml 从链接中获取html

func (*Form) ResolveSelector

func (f *Form) ResolveSelector(html string, selector map[string]Field, originUrl string) (map[string]string, error)

ResolveSelector 解析选择器

Jump to

Keyboard shortcuts

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