看到有很多python 的,然后写了个go 的,可以抓取高清图片
getp.go
复制代码 代码如下:
package main
import (
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
"strconv"
"strings"
"sync"
)
var urlist [4]string
var album chan string
var w sync.WaitGroup
var dir string
func main() {
dir = "tmp/"
err := os.Mkdir(dir, 0777)
if err != nil {
isexist := os.IsExist(err)
log.Println(isexist)
}
album = make(chan string, 200)
urlist = [4]string{"http://me2-sex.lofter.com/tag/%E7%BE%8E%E5%A5%B3%E6%91%84%E5%BD%B1", "http://me2-sex.lofter.com/tag/%E6%AC%A7%E7%BE%8E", "http://me2-sex.lofter.com/tag/%E6%A8%A1%E7%89%B9", "http://me2-sex.lofter.com/tag/%E7%BE%8E%E5%AA%9B%E9%A6%86"}
for _, v := range urlist {
for i := 1; i <= 20; i++ {
url := v + strconv.Itoa(i)
w.Add(1)
go GetAlbum(url)
w.Wait()
}
}
}
func GetAlbum(url string) {
data := GetUrl(url)
body := string(data)
part := regexp.MustCompile(`<a class="img" href="(.*)">`)
match := part.FindAllStringSubmatch(body, -1)
for _, v := range match {
album <- v[1]
w.Add(1)
go GetItem()
}
w.Done()
}
func GetItem() {
url := <-album
defer func() {
ret := recover()
if ret != nil {
log.Println(ret)
w.Done()
} else {
w.Done()
}
}()
data := GetUrl(url)
if len(data) > 10 {
body := string(data)
part := regexp.MustCompile(`bigimgsrc="/UploadFiles/2021-04-08/(.*)">
match := part.FindAllStringSubmatch(body, -1)
for _, v := range match {
str := strings.Split(v[1], "/")
length := len(str)
source := GetUrl(v[1])
name := str[length-1]
file, err := os.Create(dir + name)
if err != nil {
panic(err)
}
size, err := file.Write(source)
defer file.Close()
if err != nil {
panic(err)
}
log.Println(size)
}
}
}
func GetUrl(url string) []byte {
ret, err := http.Get(url)
if err != nil {
log.Println(url)
status := map[string]string{}
status["status"] = "400"
status["url"] = url
panic(status)
}
body := ret.Body
data, _ := ioutil.ReadAll(body)
return data
}
以上所述就是本文的全部内容了,希望对大家熟悉go语言能够有所帮助。
go语言,抓取,高清,图片
更新动态
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]