76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package downloadlogo
|
|
|
|
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
|
|
}
|