瀏覽代碼

solution type dabory added

hakjinlee 1 年之前
父節點
當前提交
0d789cc634
共有 4 個文件被更改,包括 93 次插入5 次删除
  1. 81 0
      controllers/scraper/dabory/parser.go
  2. 5 0
      controllers/scraper/tct-main.go
  3. 1 0
      model/item.go
  4. 6 5
      test/api.http

+ 81 - 0
controllers/scraper/dabory/parser.go

@@ -0,0 +1,81 @@
+package dabory
+
+import (
+	"kkscrap-go/model"
+	"log"
+	"regexp"
+	"strconv"
+	"strings"
+
+	util "kkscrap-go/controllers/scraper/util"
+
+	"github.com/PuerkitoBio/goquery"
+)
+
+func Parse(body string, item *model.ItemInfo) {
+	doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
+	util.CheckError(err)
+	doc.Find("meta").Each(func(i int, s *goquery.Selection) {
+		v, _ := s.Attr("name")
+		if v == "SolutionType" {
+			item.SolutionName = model.SolutionType(s.AttrOr("content", ""))
+		} else if v == "email" {
+			item.Emails = append(item.Emails, s.AttrOr("content", ""))
+		}
+	})
+
+	item.ItemCategory = doc.Find(".dbr-item-category").Text()
+	item.ItemName = doc.Find(".dbr-item-name").Text()
+	item.BrandName = doc.Find(".dbr-brand-name").Text()
+	str := doc.Find(".dbr-sales-price").Text()
+	str = strings.ReplaceAll(str, ",", "")
+	str = strings.ReplaceAll(str, "원", "")
+	str = strings.TrimSpace(str)
+	p, err := strconv.ParseInt(str, 10, 64)
+	if err != nil {
+		p = 0
+		log.Println(str, err)
+	}
+	item.SalesPrice = float32(p)
+	item.OriginDesc, err = doc.Find(".dbr-origin-desc").Html()
+	util.CheckError(err)
+
+	item.Images = append(item.Images, doc.Find(".dbr-image-preview").AttrOr("src", ""))
+
+	re := regexp.MustCompile(`-\d+x\d+\.`)
+	doc.Find(".dbr-image-thumb").Each(func(i int, s *goquery.Selection) {
+		img := s.AttrOr("src", "")
+		img = re.ReplaceAllString(img, ".")
+		item.Images = append(item.Images, img)
+	})
+
+	opt := model.Option{}
+	doc.Find(".dbr-option1 > option").Each(func(i int, selection *goquery.Selection) {
+		opt.Choices = append(opt.Choices, model.Choice{
+			Name: selection.Text(),
+		})
+	})
+	item.Options = append(item.Options, opt)
+
+	opt = model.Option{}
+	doc.Find(".dbr-option2 > option").Each(func(i int, selection *goquery.Selection) {
+		opt.Choices = append(opt.Choices, model.Choice{
+			Name: selection.Text(),
+		})
+	})
+	item.Options = append(item.Options, opt)
+
+	return
+}
+
+func getCurrency(body string) string {
+	reg, _ := regexp.Compile("var gdCurrencyCode = '(.*)';")
+	ss := reg.FindStringSubmatch(body)
+	return ss[1]
+}
+
+func getPrice(body string) float32 {
+	reg, _ := regexp.Compile("'setGoodsPrice'[ ]*:[ ]*'(.*)'")
+	ss := reg.FindStringSubmatch(body)
+	return util.GetFloat32(ss[1])
+}

+ 5 - 0
controllers/scraper/tct-main.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	e "github.com/dabory/abango-rest/etc"
 	"kkscrap-go/controllers/scraper/cafe24"
+	"kkscrap-go/controllers/scraper/dabory"
 	"kkscrap-go/controllers/scraper/godo"
 	"kkscrap-go/controllers/scraper/magento"
 	"kkscrap-go/controllers/scraper/shopify"
@@ -196,6 +197,8 @@ func parseSolution(t model.SolutionType, theme, uri, body string) (ret model.Ite
 
 	if t == model.SolutionTypeWooCommerce {
 		wordpress.Parse(body, &ret)
+	} else if t == model.SolutionTypeDabory {
+		dabory.Parse(body, &ret)
 	} else if t == model.SolutionTypeShopify {
 		shopify.Parse(body, &ret)
 	} else if t == model.SolutionTypeMagento {
@@ -215,6 +218,8 @@ func parseSolution(t model.SolutionType, theme, uri, body string) (ret model.Ite
 func getSolutionType(body string) (t model.SolutionType, theme string, reterr error) {
 	if strings.Contains(body, "window.CAFE24") {
 		t = model.SolutionTypeCafe24
+	} else if strings.Contains(body, "dbrshop") {
+		t = model.SolutionTypeDabory
 	} else if strings.Contains(body, "/wp-content/") {
 		t = model.SolutionTypeWooCommerce
 	} else if strings.Contains(body, "고도몰5") {

+ 1 - 0
model/item.go

@@ -37,6 +37,7 @@ type SolutionType string
 
 var (
 	SolutionTypeWooCommerce SolutionType = "WOOCOMMERCE"
+	SolutionTypeDabory      SolutionType = "dbrshop"
 	SolutionTypeShopify     SolutionType = "SHOPIFY"
 	SolutionTypeMagento     SolutionType = "MAGENTO"
 	SolutionTypeCafe24      SolutionType = "CAFE24"

+ 6 - 5
test/api.http

@@ -16,17 +16,18 @@ POST http://localhost:19080/solution-type-get
 Content-Type: application/json
 
 {
-  "url": "https://www.mangokuro.com/shop/turkey/"
+  "url": "https://nawame.daboryhost.com/item-details/TEST-0001"
 }
 ###
 POST http://localhost:19080/product-page-get
 Content-Type: application/json
 
 {
-  "solutionType": "WOOCOMMERCE",
+  "solutionType": "dbrshop",
   "themeType": "",
   "products": [
-    {"uri": "https://seoulknit.com"},
-    {"uri": "https://www.iroirotokyo.com/product/%eb%ac%b4%eb%a3%8c%eb%b0%b0%ec%86%a1-%ec%98%a4%eb%a6%ac%ed%9e%88%eb%a1%9c-%ea%b3%a4%ec%95%bd%ec%a0%a4%eb%a6%ac-%ed%8c%8c%ec%9a%b0%ec%b9%98-%ec%b9%bc%eb%a1%9c%eb%a6%ac%ec%a0%9c%eb%a1%9c%eb%b0%b1/"}
+    {"uri": "https://nawame.daboryhost.com/item-details/A000-1"}
   ]
-}
+}
+###
+GET https://nawame.daboryhost.com/item-details/A000-1