From 61108f11109693b90adfedd7656b25c1678c1f29 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sun, 18 Jun 2023 13:56:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E7=A7=BB=E5=88=B0=E6=96=B0main.go?= =?UTF-8?q?=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ main_test.go | 69 ++----------------------------------------------- 2 files changed, 75 insertions(+), 67 deletions(-) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..fb6bc03 --- /dev/null +++ b/main.go @@ -0,0 +1,73 @@ +package main + +import ( + "log" + "os" + "strconv" + "strings" + + "github.com/474420502/extractor" + "github.com/474420502/requests" +) + +type ItemList struct { + LogoUri []string `exp:"//div[@class='result-group bg-white']//img" method:"AttributeValue,src"` +} + +func main() { + ses := requests.NewSession() + tp := ses.Get("https://brandeps.com/logo/Latest?page=500") + + dp, err := os.ReadFile("logos/.record") + if err != nil { + log.Panic(err) + } + startPage, err := strconv.Atoi(string(dp)) + if err != nil { + log.Panic(err) + } + + page := tp.QueryParam("page") + for i := startPage; i < 500; i++ { + log.Println("page", i) + + // strconv.Itoa(i) + err = os.WriteFile("logos/.record", []byte(strconv.Itoa(i)), 0644) + if err != nil { + panic(err) + } + + page.IntSet(int64(i)) + res, err := tp.Execute() + if err != nil { + panic(err) + } + + // log.Println(res.ContentString()) + etor := extractor.ExtractHtml(res.Content()) + itemlist := &ItemList{} + etor.GetObjectByTag(itemlist) + if len(itemlist.LogoUri) <= 0 { + break + } + for _, uri := range itemlist.LogoUri { + + // uri = strings.Replace(uri, ".svg", ".eps", 1) + log.Println(uri) + res, err = ses.Get(uri).Execute() + if err != nil { + panic(err) + } + index := strings.LastIndex(uri, "/") + if index >= 0 { + log.Println(uri[index+1:]) + err = os.WriteFile("logos/"+uri[index+1:], res.Content(), 0644) + if err != nil { + panic(err) + } + } + + } + } + // https://brandeps.com/logo/Latest?page=4 +} diff --git a/main_test.go b/main_test.go index 470d773..9f5d2cd 100644 --- a/main_test.go +++ b/main_test.go @@ -1,75 +1,10 @@ -package downloadlogo +package main import ( - "log" - "os" - "strconv" - "strings" "testing" - - "github.com/474420502/extractor" - "github.com/474420502/requests" ) -type ItemList struct { - LogoUri []string `exp:"//div[@class='result-group bg-white']//img" method:"AttributeValue,src"` -} - func TestMain(t *testing.T) { - ses := requests.NewSession() - tp := ses.Get("https://brandeps.com/logo/Latest?page=500") - - dp, err := os.ReadFile("logos/.record") - if err != nil { - log.Panic(err) - } - startPage, err := strconv.Atoi(string(dp)) - if err != nil { - log.Panic(err) - } - - page := tp.QueryParam("page") - for i := startPage; i < 500; i++ { - log.Println("page", i) - - // strconv.Itoa(i) - err = os.WriteFile("logos/.record", []byte(strconv.Itoa(i)), 0644) - if err != nil { - panic(err) - } - - page.IntSet(int64(i)) - res, err := tp.Execute() - if err != nil { - panic(err) - } - - // log.Println(res.ContentString()) - etor := extractor.ExtractHtml(res.Content()) - itemlist := &ItemList{} - etor.GetObjectByTag(itemlist) - if len(itemlist.LogoUri) <= 0 { - break - } - for _, uri := range itemlist.LogoUri { - - // uri = strings.Replace(uri, ".svg", ".eps", 1) - log.Println(uri) - res, err = ses.Get(uri).Execute() - if err != nil { - panic(err) - } - index := strings.LastIndex(uri, "/") - if index >= 0 { - log.Println(uri[index+1:]) - err = os.WriteFile("logos/"+uri[index+1:], res.Content(), 0644) - if err != nil { - panic(err) - } - } - - } - } - // https://brandeps.com/logo/Latest?page=4 + main() }