语言:Golang
库:Iris/Colly/gorm
运行结果
text/html; charset=utf-8
It is image 20240429222029_0_0.jpg
Saved file: images\20240429222029_0_0.jpg
text/html; charset=utf-8
It is image 20240429222030_1_0.jpg
Saved file: images\20240429222030_1_0.jpg
It is image 20240429222031_1_1.jpg
Saved file: images\20240429222031_1_1.jpg
text/html; charset=utf-8
It is image 20240429222032_2_0.jpg
Saved file: images\20240429222032_2_0.jpg
text/html; charset=utf-8
It is image 20240429222033_3_0.jpg
Saved file: images\20240429222033_3_0.jpg
It is image 20240429222033_3_1.jpg
Saved file: images\20240429222033_3_1.jpg
It is image 20240429222035_3_2.jpg
Saved file: images\20240429222035_3_2.jpg
It is image 20240429222036_3_3.jpg
Saved file: images\20240429222036_3_3.jpg
It is image 20240429222036_3_4.jpg
Saved file: images\20240429222036_3_4.jpg
持久化数据
保存图片
相关代码
爬取方法:
func CrawlingDataFromXHS(requestUrl string) {c := colly.NewCollector()c.MaxDepth = 6detailC := c.Clone()// 主题编码var topicNo = 0// 图片编码var imageNo = 0c.OnRequest(func(r *colly.Request) {tools.AddHeadersForXHS(r)//_ = c.SetCookies(r.URL.Path, cookies)})// 下载指定标签 article 区域内所有的 imgc.OnHTML("div.footer a.title", func(e *colly.HTMLElement) {// 存放主题编码topicNo = e.Indexhref := e.Attr("