See a lot of Python, and then write a go, you can grab the HD image
Getp.go
Copy Code code as follows:
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?page=", "http:// Me2-sex.lofter.com/tag/%e6%ac%a7%e7%be%8e?page= "," http://me2-sex.lofter.com/tag/%E6%A8%A1%E7%89%B9?page= "," Http://me2-sex.lofter.com/tag/%E7%BE%8E%E5%AA%9B%E9%A6%86?page= "}
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= ' (. *) "")
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
}
The above is the entire content of this article, I hope to be familiar with the go language can help.