Advertisement
Guest User

Untitled

a guest
Nov 21st, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.03 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "io"
  6.     "math/rand"
  7.     "net/http"
  8.     "os"
  9.     "strings"
  10.     "sync"
  11.     "time"
  12. )
  13.  
  14. func path() string {
  15.     var str string
  16.     for i := 0; i < 5; i++ {
  17.         str += fmt.Sprintf("%x", rand.Intn(16))
  18.     }
  19.     return "http://gs.3g.cn/D/" + str + "/w"
  20. }
  21.  
  22. const dir = "pics/"
  23.  
  24. func main() {
  25.     var wg sync.WaitGroup
  26.     for{
  27.         wg.Add(100)
  28.         for i:=0; i < 100; i++{
  29.             go func() {
  30.                 p := path()
  31.                 resp, err := http.Get(p)
  32.                 if err != nil {
  33.                     fmt.Println("err")
  34.                 }
  35.                 urll := resp.Request.URL.String()
  36.                 if strings.HasPrefix(urll, "http://gs.3g.cn/D/"){
  37.                     wg.Done()
  38.                     return
  39.                 }
  40.                 urll = strings.Replace(urll, "&t=image/jpeg&w=100&h=200", "", -1)
  41.                 urll = strings.Replace(urll, "&t=image/png&w=100&h=200", "", -1)
  42.                 urll = strings.Replace(urll, "&t=application/zip&w=100&h=200", "", -1)
  43.                 urll = strings.Replace(urll, "&t=video/mp4&w=100&h=200", "", -1)
  44.  
  45.                 urll = strings.Replace(urll, "/mms/v14/index.html?u=http%3A%2F%2Fgosms.gomocdn.com%2F", "/", -1)
  46.                 fmt.Println(urll)
  47.                 if strings.HasSuffix(urll,"200"){
  48.                     wg.Done()
  49.                     return
  50.                 }
  51.                 picres, _ := http.Get(urll)
  52.                 if strings.Contains(urll,"png"){
  53.                     pic, _ := os.Create(dir + time.Now().String()+ ".png")
  54.                     defer pic.Close()
  55.                     io.Copy(pic, picres.Body)
  56.                     wg.Done()
  57.                 }
  58.                 if strings.Contains(urll,"jpg"){
  59.                     pic, _ := os.Create(dir + time.Now().String()+ ".jpg")
  60.                     defer pic.Close()
  61.                     io.Copy(pic, picres.Body)
  62.                     wg.Done()
  63.                 }
  64.                 if strings.Contains(urll,"jpeg"){
  65.                     pic, _ := os.Create(dir + time.Now().String()+ ".jpeg")
  66.                     defer pic.Close()
  67.                     io.Copy(pic, picres.Body)
  68.                     wg.Done()
  69.                 }
  70.                 if strings.Contains(urll,"zip"){
  71.                     pic, _ := os.Create(dir + time.Now().String()+ ".zip")
  72.                     defer pic.Close()
  73.                     io.Copy(pic, picres.Body)
  74.                     wg.Done()
  75.                 }
  76.                 if strings.Contains(urll,"mp4"){
  77.                     pic, _ := os.Create(dir + time.Now().String()+ ".mp4")
  78.                     defer pic.Close()
  79.                     io.Copy(pic, picres.Body)
  80.                     wg.Done()
  81.                 }
  82.  
  83.             }()
  84.         }
  85.         wg.Wait()
  86.     }
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement