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() }