💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
设置图片前置路径 ```go 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", ImagePrefix: func(form *articleSpider.Form, imageName string) string { return "image" }}, }, } s := articleSpider.NewSpider(f, articleSpider.Normal) s.Start() } ``` 在excel中显示为 ![](https://img.kancloud.cn/e2/ae/e2ae160c52ad0ea23198030ba72dcea3_361x257.png) >[info]**ImagePrefix**不会生成文件夹,只会在结果添加路径 <br/><br/> 设置图片子文件夹 ```go 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", ImageDir: "[date:Ymd]"}, }, } s := articleSpider.NewSpider(f, articleSpider.Normal) s.Start() } ``` excel结果 ![](https://img.kancloud.cn/4b/73/4b73c49a050cb26c6c7fa468a3b1d8ae_356x259.png) <br/> 图片路径 ![](https://img.kancloud.cn/1b/85/1b850b7670ea13dcf3e1a3c60c9edbe3_368x291.png) <br/> **ImageDir**支持三种变量模式 * [date:Ymd] 日期文件夹,例:**ImageDir: "[date:Ymd]"** 或 **ImageDir: "[date:md]"** * [random:1-100] 随机数字 例:**ImageDir: "[date:1-200]"** ,随机1到200生成文件夹 * [singleField:name] 根据其他字段生成文件夹 例:**ImageDir: "[singleField:title]"** <br/><br/> 例子: 随机数字文件夹 ``` 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", ImageDir: "[random:1-200]"}, }, } s := articleSpider.NewSpider(f, articleSpider.Normal) s.Start() } ``` <br/><br/> 根据文章标题生成文件夹 ``` 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{ "title": {Types: articleSpider.Text, Selector: " dd > h3 > a"}, "img": {Types: articleSpider.Image, Selector: " dt > a > img", ImageDir: "[singleField:title]"}, }, } s := articleSpider.NewSpider(f, articleSpider.Normal) s.Start() } ```