ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
**https://www.shouyouzhijia.net/xinwen_1/** ,这是一个栏目的列表 新建go文件,创建form和spider对象 ```go package main import articleSpider "github.com/PeterYangs/article-spider/v3" func main() { f := articleSpider.Form{ } 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", } 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]/", } s := articleSpider.NewSpider(f, articleSpider.Normal) s.Start() } ``` >[info]第二页 **/xinwen_2/** ,第三页 **/xinwen_3/**,把页码的数值替换成 **[PAGE]** <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, } s := articleSpider.NewSpider(f, articleSpider.Normal) s.Start() } ``` >[info]从第一页开始,爬三页 <br/><br/> 配置列表选择器和详情页a链接选择器 ``` 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", } s := articleSpider.NewSpider(f, articleSpider.Normal) s.Start() } ``` >[info]注意,**HrefSelector**是相对于**ListSelector**开始计算的,不要放完整选择器 <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", DetailFields: map[string]articleSpider.Field{ "title": {Types: articleSpider.Text, Selector: "body > div.Min-cent.W1200 > div.Min_L > div.Left_top > h1"}, "img": {Types: articleSpider.Image, Selector: "#content img:nth-child(1)"}, }, } s := articleSpider.NewSpider(f, articleSpider.Normal) //s.Debug() s.Start() } ```