优化爬取逻辑-后缀名动态获取,及添加地址兼容判断
This commit is contained in:
parent
fc6930c0f1
commit
6e8cd8403f
@ -30,9 +30,16 @@ func start() {
|
|||||||
|
|
||||||
func get(num int) {
|
func get(num int) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
fileName := strconv.Itoa(num) + ".jpg"
|
|
||||||
imgSlice := strings.Split(url, "_")
|
// 兼容未携带斜杆的地址
|
||||||
imgUrl := host + imgSlice[0] + "_" + fmt.Sprintf("%02d", num) + ".jpg"
|
if url[0] != '/' {
|
||||||
|
url = "/" + url
|
||||||
|
}
|
||||||
|
|
||||||
|
urlSlice := strings.Split(url, "_") // 取URL组装
|
||||||
|
fileSlice := strings.Split(urlSlice[1], ".") // 取后缀名
|
||||||
|
fileName := strconv.Itoa(num) + "." + fileSlice[1] // 组装文件名
|
||||||
|
imgUrl := host + urlSlice[0] + "_" + fmt.Sprintf("%02d", num) + "." + fileSlice[1] // 组装图片URL
|
||||||
fmt.Println("获取图片:" + imgUrl)
|
fmt.Println("获取图片:" + imgUrl)
|
||||||
|
|
||||||
resp, err := http.Get(imgUrl)
|
resp, err := http.Get(imgUrl)
|
||||||
|
Loading…
Reference in New Issue
Block a user