~~~
package main
import (
articleSpider "github.com/PeterYangs/article-spider/v3"
)
func main() {
f := articleSpider.Form{
Host: "https://www.shouyouzhijia.net",
Channel: "/xinwen_[PAGE]/",
PageStart: 1,
Length: 3,
ListSelector: "body > div.main.newex.clearfix > div.LC_lef > div.lef_content > dl",
HrefSelector: " dd > h3 > a",
ListFields: map[string]articleSpider.Field{
"img": {Types: articleSpider.Image, Selector: " dt > a > img"},
},
//只允许下载png和jpg两个类型的图片
AllowImageExtension: []string{"png", "jpg"},
}
s := articleSpider.NewSpider(f, articleSpider.Normal)
s.Start()
}
~~~
>[info]**AllowImageExtension**在不设置的情况下,默认是"png", "jpg", "jpeg", "gif", "jfif"
<br/><br/>
但是有时候有的图片是没有拓展的,可以这样设置
~~~
package main
import (
articleSpider "github.com/PeterYangs/article-spider/v3"
)
func main() {
f := articleSpider.Form{
Host: "http://www.lfdsw.cn",
Channel: "/game/page/[PAGE]/",
PageStart: 1,
Length: 3,
ListSelector: "body > main > div > div.category.uk-background-muted.uk-margin-bottom > div > div.uk-grid-small.uk-grid > div",
HrefSelector: " div > a.icon",
ListFields: map[string]articleSpider.Field{
"img": {Types: articleSpider.Image, Selector: " div > a.icon > img"},
},
DisableImageExtensionCheck: true,
}
s := articleSpider.NewSpider(f, articleSpider.Normal)
s.Start()
}
~~~
>[info]**DisableImageExtensionCheck**在设置为true后,会跳过图片拓展检查,但是所有的图片拓展会强制下载为png