Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
2d969077
提交
2d969077
authored
11月 07, 2019
作者:
梁业锦
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
重新排布了爬虫的代码结构
上级
eb49473c
全部展开
显示空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
143 行增加
和
2629 行删除
+143
-2629
UniqloSpider.java
...va/com/diaoyun/zion/chinafrica/bis/impl/UniqloSpider.java
+143
-4
AdidasSpiderParse.java
...om/diaoyun/zion/master/util/spider/AdidasSpiderParse.java
+0
-132
CoachSpiderParse.java
...com/diaoyun/zion/master/util/spider/CoachSpiderParse.java
+0
-160
EspritSpiderParse.java
...om/diaoyun/zion/master/util/spider/EspritSpiderParse.java
+0
-150
HMSpiderParse.java
...va/com/diaoyun/zion/master/util/spider/HMSpiderParse.java
+0
-178
LeviSpiderParse.java
.../com/diaoyun/zion/master/util/spider/LeviSpiderParse.java
+0
-150
LilySpiderParse.java
.../com/diaoyun/zion/master/util/spider/LilySpiderParse.java
+0
-64
MassimoDuttiSpiderParse.java
...oyun/zion/master/util/spider/MassimoDuttiSpiderParse.java
+0
-161
MocoSpiderParse.java
.../com/diaoyun/zion/master/util/spider/MocoSpiderParse.java
+0
-156
OchirlySpiderParse.java
...m/diaoyun/zion/master/util/spider/OchirlySpiderParse.java
+0
-158
SpiderUtil.java
.../java/com/diaoyun/zion/master/util/spider/SpiderUtil.java
+0
-571
UnderArmourSpiderParse.java
...aoyun/zion/master/util/spider/UnderArmourSpiderParse.java
+0
-137
UniqloSpiderParse.java
...om/diaoyun/zion/master/util/spider/UniqloSpiderParse.java
+0
-154
UrbanRevivoSpiderParse.java
...aoyun/zion/master/util/spider/UrbanRevivoSpiderParse.java
+0
-146
VansSpiderParse.java
.../com/diaoyun/zion/master/util/spider/VansSpiderParse.java
+0
-137
ZaraSpiderParse.java
.../com/diaoyun/zion/master/util/spider/ZaraSpiderParse.java
+0
-171
没有找到文件。
src/main/java/com/diaoyun/zion/chinafrica/bis/impl/UniqloSpider.java
浏览文件 @
2d969077
...
...
@@ -2,10 +2,11 @@ package com.diaoyun.zion.chinafrica.bis.impl;
import
com.diaoyun.zion.chinafrica.bis.IItemSpider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.
ProductResponse
;
import
com.diaoyun.zion.chinafrica.vo.
*
;
import
com.diaoyun.zion.master.util.HttpClientUtil
;
import
com.diaoyun.zion.master.util.TranslateHelper
;
import
com.diaoyun.zion.master.util.spider.UniqloSpiderParse
;
import
com.diaoyun.zion.master.util.SpiderUtil
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -13,6 +14,7 @@ import org.springframework.stereotype.Component;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
import
java.util.*
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
...
...
@@ -32,7 +34,6 @@ public class UniqloSpider implements IItemSpider {
/**
* Uniqlo 数据爬虫
* @see UniqloSpiderParse#formatProductResponse 格式化数据方法
* @param targetUrl 接收的商品详情路径
* @return 格式化与翻译后的 Json 数据
*/
...
...
@@ -48,11 +49,149 @@ public class UniqloSpider implements IItemSpider {
String
priceContent
=
HttpClientUtil
.
getContentByUrl
(
priceUrl
,
PlatformEnum
.
UNIQLO
.
getValue
());
JSONObject
resultJson
=
JSONObject
.
fromObject
(
content
);
JSONObject
priceJson
=
JSONObject
.
fromObject
(
priceContent
);
ProductResponse
productResponse
=
UniqloSpiderParse
.
formatProductResponse
(
resultJson
,
priceJson
,
pId
);
ProductResponse
productResponse
=
formatProductResponse
(
resultJson
,
priceJson
,
pId
);
resultJson
=
JSONObject
.
fromObject
(
productResponse
);
// 翻译
TranslateHelper
.
translateProductResponse
(
resultJson
);
return
resultJson
;
}
/**
* 返回格式化数据
* @param dataMap 调用优衣库网页接口接收的主要商品数据
* @param pId 商品链接截取的商品id
* @return
*/
private
ProductResponse
formatProductResponse
(
JSONObject
dataMap
,
JSONObject
priceJson
,
String
pId
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 商品基本信息
ItemInfo
itemInfo
=
new
ItemInfo
();
// 取 summary 节点对象
JSONObject
summaryObj
=
dataMap
.
getJSONObject
(
"summary"
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////////////////////
itemInfo
.
setShopName
(
PlatformEnum
.
UNIQLO
.
getLabel
());
itemInfo
.
setShopUrl
(
"https://www.uniqlo.cn/product-detail.html"
);
itemInfo
.
setItemId
(
pId
);
itemInfo
.
setTitle
(
summaryObj
.
getString
(
"fullName"
));
//////////////////////////////////// 获取商品基本信息End(图片下取) ////////////////////////////////////////////
// 取 rows 节点数组
JSONArray
rowsArr
=
dataMap
.
getJSONArray
(
"rows"
);
for
(
int
i
=
0
;
i
<
rowsArr
.
size
();
i
++)
{
JSONObject
rowsObj
=
rowsArr
.
getJSONObject
(
i
);
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////////////////////
Set
<
ProductProp
>
propSetColor
=
new
HashSet
<>(
16
);
ProductProp
productPropColor
=
new
ProductProp
();
// 颜色id
String
colorNo
=
rowsObj
.
getString
(
"colorNo"
);
productPropColor
.
setPropId
(
colorNo
);
// 颜色名
String
colorName
=
rowsObj
.
getString
(
"style"
);
productPropColor
.
setPropName
(
colorName
);
// 颜色图片
String
imageUrl
=
"https://www.uniqlo.cn/hmall/test/"
+
pId
+
"/sku/561/"
+
colorNo
+
".jpg"
;
productPropColor
.
setImage
(
imageUrl
);
if
(
i
==
0
)
{
itemInfo
.
setPic
(
imageUrl
);
}
propSetColor
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSetColor
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSetColor
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSetColor
);
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
///////////////////////// 获取商品尺码属性 ////////////////////
Set
<
ProductProp
>
sizePropSetSize
=
new
HashSet
<>();
ProductProp
productPropSize
=
new
ProductProp
();
String
size
=
rowsObj
.
getString
(
"sizeText"
);
productPropSize
.
setPropName
(
size
);
String
sizeNo
=
rowsObj
.
getString
(
"skuId"
);
productPropSize
.
setPropId
(
sizeNo
);
sizePropSetSize
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSetSize
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSetSize
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSetSize
);
}
///////////////////////// 获取商品尺码属性 END////////////////////
String
skuStr
=
";"
+
colorNo
+
";"
+
sizeNo
+
";"
;
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
// 设置:可用库存值,Uniqlo 未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
OriginalPrice
originalPrice
=
new
OriginalPrice
();
// 获取商品的原始价
String
fullPrice
=
summaryObj
.
getString
(
"originPrice"
);
// TODO 转换汇率,目前商品单位是人民币
fullPrice
=
SpiderUtil
.
exchangeRate
(
fullPrice
);
originalPrice
.
setPrice
(
fullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
//////////////////////////////////// 获取原始价 END//////////////////////////////////
//////////////////////////////////// 获取促销价 //////////////////////////////////
// 取 summary 节点对象
JSONObject
summaryPriceObj
=
priceJson
.
getJSONArray
(
"resp"
).
getJSONObject
(
0
).
getJSONObject
(
"summary"
);
ProductPromotion
productPromotion
=
new
ProductPromotion
();
// 获取商品的促销价
String
promotionPrice
=
summaryPriceObj
.
getString
(
"maxPrice"
);
// TODO 转换汇率,目前商品单位是人民币
promotionPrice
=
SpiderUtil
.
exchangeRate
(
promotionPrice
);
productPromotion
.
setSkuStr
(
skuStr
);
productPromotion
.
setPrice
(
promotionPrice
);
productResponse
.
setPrice
(
promotionPrice
);
productResponse
.
setSalePrice
(
promotionPrice
+
"-"
+
fullPrice
);
promotionList
.
add
(
productPromotion
);
//////////////////////////////////// 获取促销价 END//////////////////////////////////
}
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setPromotionFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
UNIQLO
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/AdidasSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
java.util.*
;
import
static
com
.
diaoyun
.
zion
.
master
.
util
.
spider
.
SpiderUtil
.
exchangeRate
;
/**
* Adidas 数据爬虫
* @see com.diaoyun.zion.chinafrica.bis.impl.AdidasSpider
* @author 爱酱油不爱醋
*/
public
class
AdidasSpiderParse
{
/**
* 格式化返回数据
* @param content 主要的页面数据
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
String
content
,
String
pId
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 解析为 Document 对象
Document
document
=
Jsoup
.
parse
(
content
);
// 获取商品的价格、颜色、标题、图片、尺码属性
String
fullPrice
=
document
.
select
(
"input[id=salePrice]"
).
attr
(
"value"
);
String
pColor
=
document
.
select
(
"input[id=colorDisPaly]"
).
attr
(
"value"
);
String
pTitle
=
document
.
select
(
"input[id=itemTitle]"
).
attr
(
"value"
);
String
pImg
=
document
.
select
(
"input[id=shoppingcartpic]"
).
attr
(
"value"
);
List
<
String
>
pSizeList
=
document
.
select
(
"div[class=overview product-size]"
)
.
select
(
"ul"
).
select
(
"li"
).
eachText
();
//////////////////////////////////// 获取商品基本信息 ////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
PlatformEnum
.
ADIDAS
.
getLabel
());
itemInfo
.
setShopUrl
(
"https://www.adidas.com"
);
itemInfo
.
setItemId
(
pId
);
itemInfo
.
setTitle
(
pTitle
);
itemInfo
.
setPic
(
pImg
);
//////////////////////////////////// 获取商品基本信息End /////////////////////////
for
(
int
i
=
0
;
i
<
pSizeList
.
size
();
i
++)
{
// 库存对应的id(颜色id + 尺码id)
String
skuStr
=
";"
+
pId
+
";"
+
pSizeList
.
get
(
i
)
+
";"
;
///////////////////////// 获取商品尺码属性 ////////////////////
Set
<
ProductProp
>
sizePropSet
=
new
HashSet
<>();
ProductProp
productPropSize
=
new
ProductProp
();
productPropSize
.
setPropId
(
pSizeList
.
get
(
i
));
productPropSize
.
setPropName
(
pSizeList
.
get
(
i
));
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
///////////////////////// 获取商品尺码属性 END////////////////////
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
// 设置:可用库存值,Zara 未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
OriginalPrice
originalPrice
=
new
OriginalPrice
();
// 获取商品的原始价
// TODO 转换汇率,目前商品单位是人民币
String
originalFullPrice
=
exchangeRate
(
fullPrice
);
originalPrice
.
setPrice
(
originalFullPrice
);
productResponse
.
setPrice
(
originalFullPrice
);
productResponse
.
setSalePrice
(
originalFullPrice
+
"-"
+
originalFullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
//////////////////////////////////// 获取原始价 END///////////////////////////////
}
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////
Set
<
ProductProp
>
propSet
=
new
HashSet
<>(
16
);
ProductProp
productPropColor
=
new
ProductProp
();
// 颜色描述
productPropColor
.
setPropId
(
pId
);
productPropColor
.
setPropName
(
pColor
);
productPropColor
.
setImage
(
pImg
);
propSet
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSet
);
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
ADIDAS
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/CoachSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
java.util.*
;
import
java.util.regex.Pattern
;
import
static
com
.
diaoyun
.
zion
.
master
.
util
.
spider
.
SpiderUtil
.
exchangeRate
;
/**
* COACH(蔻驰) 爬虫数据解析
* @see com.diaoyun.zion.chinafrica.bis.impl.CoachSpider
* @author 爱酱油不爱醋
*/
public
class
CoachSpiderParse
{
/**
* 格式化返回数据
* @param dataMap 主要的Json数据
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
JSONObject
dataMap
,
String
pId
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 取 data 节点对象
JSONObject
dataObj
=
dataMap
.
getJSONObject
(
"data"
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
PlatformEnum
.
COACH
.
getLabel
());
itemInfo
.
setShopUrl
(
"https://china.coach.com"
);
itemInfo
.
setItemId
(
pId
);
itemInfo
.
setTitle
(
dataObj
.
getString
(
"name"
));
//////////////////////////////////// 获取商品基本信息(图片下取)End /////////////////////////
List
<
String
>
sizeNoList
=
new
ArrayList
<>();
List
<
String
>
colorNoList
=
new
ArrayList
<>();
// 取 attributes 节点数组
JSONArray
attributesArr
=
dataObj
.
getJSONArray
(
"attributes"
);
for
(
int
i
=
0
;
i
<
attributesArr
.
size
();
i
++)
{
///////////////////////// 获取商品颜色属性 ////////////////////////////////////////////////////////////////
// 0 位为颜色属性
if
(
i
==
0
)
{
// 取 values 节点数组
JSONArray
valuesArr
=
attributesArr
.
getJSONObject
(
i
).
getJSONArray
(
"values"
);
Set
<
ProductProp
>
propSet
=
new
HashSet
<>(
16
);
for
(
int
j
=
0
;
j
<
valuesArr
.
size
();
j
++)
{
JSONObject
valuesObj
=
valuesArr
.
getJSONObject
(
j
);
// 获取图片路径
String
imageUrl
=
valuesObj
.
getString
(
"image"
);
// 设置商品基本信息的图片
if
(
i
==
0
)
{
itemInfo
.
setPic
(
imageUrl
);
}
ProductProp
productPropColor
=
new
ProductProp
();
String
colorNo
=
valuesObj
.
getString
(
"value_index"
);
colorNoList
.
add
(
colorNo
);
productPropColor
.
setPropId
(
colorNo
);
productPropColor
.
setPropName
(
valuesObj
.
getString
(
"label"
));
productPropColor
.
setImage
(
imageUrl
);
propSet
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSet
);
}
}
///////////////////////// 获取商品颜色属性End ////////////////////////////////////////////////////////////////
///////////////////////// 获取商品尺码属性 ////////////////////////////////////////////////////////////////
// 1 位为尺寸属性(有的商品不一定会存在,如手提包)
}
else
if
(
i
==
1
)
{
// 取 values 节点数组
JSONArray
valuesArr
=
attributesArr
.
getJSONObject
(
i
).
getJSONArray
(
"values"
);
Set
<
ProductProp
>
sizePropSet
=
new
HashSet
<>();
for
(
int
j
=
0
;
j
<
valuesArr
.
size
();
j
++)
{
JSONObject
valuesObj
=
valuesArr
.
getJSONObject
(
j
);
ProductProp
productPropSize
=
new
ProductProp
();
String
sizeNo
=
valuesObj
.
getString
(
"value_index"
);
productPropSize
.
setPropId
(
sizeNo
);
sizeNoList
.
add
(
sizeNo
);
productPropSize
.
setPropName
(
valuesObj
.
getString
(
"label"
));
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
///////////////////////// 获取商品尺码属性 END/////////////////////////////////////////////////////
}
}
}
for
(
String
colorNo
:
colorNoList
)
{
for
(
String
sizeNo
:
sizeNoList
)
{
// 设置 skuStr
String
skuStr
=
";"
+
colorNo
+
";"
+
sizeNo
+
";"
;
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
// 设置:可用库存值,未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
// 获取商品的原始价(存在优惠价格)
OriginalPrice
originalPrice
=
new
OriginalPrice
();
String
fullPrice
=
Pattern
.
compile
(
"[^0-9]"
).
matcher
(
dataObj
.
getString
(
"price"
)).
replaceAll
(
""
).
trim
();
// TODO 转换汇率,目前商品单位是人民币
fullPrice
=
exchangeRate
(
fullPrice
);
productResponse
.
setPrice
(
fullPrice
);
productResponse
.
setSalePrice
(
fullPrice
+
"-"
+
fullPrice
);
originalPrice
.
setPrice
(
fullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
//////////////////////////////////// 获取原始价 END //////////////////////////////////
}
}
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
COACH
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/EspritSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
java.util.*
;
import
static
com
.
diaoyun
.
zion
.
master
.
util
.
spider
.
SpiderUtil
.
exchangeRate
;
/**
* Esprit 数据爬虫
* @see com.diaoyun.zion.chinafrica.bis.impl.EspritSpider
* @author 爱酱油不爱醋
*/
public
class
EspritSpiderParse
{
/**
* 格式化返回数据
* @param dataMap 主要的Json数据
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
JSONObject
dataMap
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 取 product 下的 details 节点对象
JSONObject
detailsObj
=
dataMap
.
getJSONObject
(
"product"
).
getJSONObject
(
"details"
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
PlatformEnum
.
ESPRIT
.
getLabel
());
itemInfo
.
setShopUrl
(
"https://www.esprit.cn"
);
itemInfo
.
setItemId
(
detailsObj
.
getString
(
"code"
));
itemInfo
.
setTitle
(
detailsObj
.
getString
(
"title"
));
//////////////////////////////////// 获取商品基本信息(图片下取)End /////////////////////////
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////////////////////
// 取 options 的0位的 value 节点数组
JSONArray
values_0_Arr
=
detailsObj
.
getJSONArray
(
"options"
).
getJSONObject
(
0
).
getJSONArray
(
"values"
);
List
<
String
>
colorNoList
=
new
ArrayList
<>();
Set
<
ProductProp
>
propSet
=
new
HashSet
<>(
16
);
for
(
int
i
=
0
;
i
<
values_0_Arr
.
size
();
i
++)
{
JSONObject
values_0_Obj
=
values_0_Arr
.
getJSONObject
(
i
);
// 获取图片路径
String
imageUrl
=
values_0_Obj
.
getJSONArray
(
"images"
).
getJSONObject
(
0
).
getString
(
"url"
);
// 设置商品基本信息的图片
if
(
i
==
0
)
{
itemInfo
.
setPic
(
imageUrl
);
}
ProductProp
productPropColor
=
new
ProductProp
();
String
colorNo
=
values_0_Obj
.
getString
(
"code"
);
colorNoList
.
add
(
colorNo
);
productPropColor
.
setPropId
(
colorNo
);
productPropColor
.
setPropName
(
values_0_Obj
.
getString
(
"displayName"
));
productPropColor
.
setImage
(
imageUrl
);
propSet
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSet
);
}
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
///////////////////////// 获取商品尺码属性 ////////////////////////////////////////////////////////////////
// 取 options 的 1 位的 value 节点数组
List
<
String
>
sizeNoList
=
new
ArrayList
<>();
Set
<
ProductProp
>
sizePropSet
=
new
HashSet
<>();
JSONArray
values_1_Arr
=
detailsObj
.
getJSONArray
(
"options"
).
getJSONObject
(
1
).
getJSONArray
(
"values"
);
for
(
int
i
=
0
;
i
<
values_1_Arr
.
size
();
i
++)
{
JSONObject
values_1_Obj
=
values_1_Arr
.
getJSONObject
(
i
);
ProductProp
productPropSize
=
new
ProductProp
();
String
sizeNo
=
values_1_Obj
.
getString
(
"code"
);
productPropSize
.
setPropId
(
sizeNo
);
sizeNoList
.
add
(
sizeNo
);
productPropSize
.
setPropName
(
values_1_Obj
.
getString
(
"displayName"
));
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
///////////////////////// 获取商品尺码属性 END/////////////////////////////////////////////////////
}
for
(
String
colorNo
:
colorNoList
)
{
for
(
String
sizeNo
:
sizeNoList
)
{
// 设置 skuStr
String
skuStr
=
";"
+
colorNo
+
";"
+
sizeNo
+
";"
;
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
// 设置:可用库存值,Zara 未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
OriginalPrice
originalPrice
=
new
OriginalPrice
();
// 获取商品的原始价
String
fullPrice
=
detailsObj
.
getJSONObject
(
"salePrice"
).
getString
(
"amount"
);
// TODO 转换汇率,目前商品单位是人民币
fullPrice
=
exchangeRate
(
fullPrice
);
originalPrice
.
setPrice
(
fullPrice
);
productResponse
.
setPrice
(
fullPrice
);
productResponse
.
setSalePrice
(
fullPrice
+
"-"
+
fullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
//////////////////////////////////// 获取原始价 END//////////////////////////////////
}
}
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
ESPRIT
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/HMSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
com.diaoyun.zion.master.util.JsoupUtil
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
org.jsoup.nodes.Element
;
import
org.jsoup.select.Elements
;
import
java.math.BigDecimal
;
import
java.util.*
;
import
static
com
.
diaoyun
.
zion
.
master
.
util
.
spider
.
SpiderUtil
.
exchangeRate
;
/**
* H&M 爬虫数据解析
* @see com.diaoyun.zion.chinafrica.bis.impl.HmSpider
* @author 爱酱油不爱醋
*/
public
class
HMSpiderParse
{
/**
* 格式化返回数据
* @param content 页面数据
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
String
content
)
{
// targetUrl=https://m2.hm.com/m/zh_cn/productpage.0806412004.html
// 获取主要数据并将转换 Json 数据及 Document 对象
String
detailStr
=
JsoupUtil
.
getScriptContent
(
content
,
"productArticleDetails"
);
int
firstBrackets
=
detailStr
.
indexOf
(
"{"
);
int
lastbrackets
=
detailStr
.
lastIndexOf
(
"}"
);
String
resultStr
=
detailStr
.
substring
(
firstBrackets
,
lastbrackets
+
1
);
resultStr
=
resultStr
.
replaceAll
(
"\'"
,
"\""
)
.
replaceAll
(
"\"image\": isDesktop [?] "
,
""
)
.
replaceAll
(
"\"fullscreen\": isDesktop [?] "
,
""
)
.
replaceAll
(
"\"zoom\": isDesktop [?] "
,
""
);
JSONObject
dataMap
=
JSONObject
.
fromObject
(
resultStr
);
Document
document
=
Jsoup
.
parse
(
content
);
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
PlatformEnum
.
HM
.
getLabel
());
itemInfo
.
setShopUrl
(
"https://www2.hm.com/"
);
itemInfo
.
setItemId
(
document
.
select
(
"div[class=article-code]"
).
select
(
"li"
).
text
());
itemInfo
.
setTitle
(
document
.
select
(
"h1[class=primary product-item-headline]"
).
text
());
//////////////////////////////////// 获取商品基本信息(图片下取)End /////////////////////////
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////////////////////
// 取页面的数据
Elements
colorEle
=
document
.
select
(
"div[class=mini-slider]"
).
select
(
"ul[class=inputlist clearfix]"
).
select
(
"li"
);
Map
<
String
,
String
>
colorMap
=
new
HashMap
<>(
16
);
Set
<
ProductProp
>
propSet
=
new
HashSet
<>(
16
);
for
(
Element
element
:
colorEle
)
{
ProductProp
productPropColor
=
new
ProductProp
();
String
color
=
element
.
select
(
"a"
).
attr
(
"data-color"
);
String
colorNo
=
element
.
select
(
"a"
).
attr
(
"data-articlecode"
);
String
imgUrl
=
element
.
select
(
"noscript"
).
attr
(
"data-src"
);
colorMap
.
put
(
colorNo
,
color
);
itemInfo
.
setPic
(
imgUrl
);
productPropColor
.
setPropId
(
colorNo
);
productPropColor
.
setPropName
(
color
);
productPropColor
.
setImage
(
imgUrl
);
propSet
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSet
);
}
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
///////////////////////// 获取商品尺码属性 ///////////////////////////////////////////////////////////
Map
<
String
,
String
>
sizeMap
=
new
HashMap
<>(
16
);
Map
<
String
,
Map
<
String
,
String
>>
colorHaveSizeMap
=
new
HashMap
<>(
16
);
Set
<
ProductProp
>
sizePropSet
=
new
HashSet
<>();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
colorMap
.
entrySet
())
{
JSONArray
sizeArr
=
dataMap
.
getJSONObject
(
entry
.
getKey
()).
getJSONArray
(
"sizes"
);
for
(
int
i
=
0
;
i
<
sizeArr
.
size
();
i
++)
{
JSONObject
sizeObj
=
sizeArr
.
getJSONObject
(
i
);
ProductProp
productPropSize
=
new
ProductProp
();
String
sizeNo
=
sizeObj
.
getString
(
"sizeCode"
);
String
size
=
sizeObj
.
getString
(
"name"
);
sizeMap
.
put
(
sizeNo
,
size
);
productPropSize
.
setPropId
(
sizeNo
);
productPropSize
.
setPropName
(
size
);
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
}
colorHaveSizeMap
.
put
(
entry
.
getKey
(),
sizeMap
);
}
///////////////////////// 获取商品尺码属性 END/////////////////////////////////////////////////////
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
// 获取价格
String
fullPrice
=
document
.
select
(
"div[class=primary-row product-item-price]"
).
text
();
fullPrice
=
SpiderUtil
.
retainNumber
(
fullPrice
);
// TODO 转换汇率,目前商品单位是人民币
fullPrice
=
exchangeRate
(
fullPrice
);
BigDecimal
priceOld
=
new
BigDecimal
(
fullPrice
);
BigDecimal
div
=
new
BigDecimal
(
"100"
);
fullPrice
=
priceOld
.
divide
(
div
,
2
,
BigDecimal
.
ROUND_DOWN
).
toString
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
for
(
Map
.
Entry
<
String
,
Map
<
String
,
String
>>
colorEntry
:
colorHaveSizeMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
String
>
sizeEntry
:
sizeMap
.
entrySet
())
{
// 设置 skuStr
String
skuStr
=
";"
+
colorEntry
.
getKey
()
+
";"
+
sizeEntry
.
getKey
()
+
";"
;
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// H&M 尚未可用的库存
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStock
.
setSellableQuantity
(
999
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
OriginalPrice
originalPrice
=
new
OriginalPrice
();
originalPrice
.
setSkuStr
(
skuStr
);
originalPrice
.
setPrice
(
fullPrice
);
originalPriceList
.
add
(
originalPrice
);
productResponse
.
setPrice
(
fullPrice
);
productResponse
.
setSalePrice
(
fullPrice
+
"-"
+
fullPrice
);
//////////////////////////////////// 获取原始价 END//////////////////////////////////
}
}
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
HM
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/LeviSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
java.util.*
;
import
static
com
.
diaoyun
.
zion
.
master
.
util
.
spider
.
SpiderUtil
.
exchangeRate
;
/**
* Levi(李维斯) 爬虫数据解析
* @see com.diaoyun.zion.chinafrica.bis.impl.LeviSpider
* @author 爱酱油不爱醋
*/
public
class
LeviSpiderParse
{
/**
* 格式化返回数据
* @param dataMap 主要的Json数据
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
JSONObject
dataMap
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 取 product 下的 details 节点对象
JSONObject
detailsObj
=
dataMap
.
getJSONObject
(
"product"
).
getJSONObject
(
"details"
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
PlatformEnum
.
LEVI
.
getLabel
());
itemInfo
.
setShopUrl
(
"https://www.levi.com"
);
itemInfo
.
setItemId
(
detailsObj
.
getString
(
"code"
));
itemInfo
.
setTitle
(
detailsObj
.
getString
(
"title"
));
//////////////////////////////////// 获取商品基本信息(图片下取)End /////////////////////////
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////////////////////
// 取 options 的0位的 value 节点数组
JSONArray
values_0_Arr
=
detailsObj
.
getJSONArray
(
"options"
).
getJSONObject
(
0
).
getJSONArray
(
"values"
);
List
<
String
>
colorNoList
=
new
ArrayList
<>();
Set
<
ProductProp
>
propSet
=
new
HashSet
<>(
16
);
for
(
int
i
=
0
;
i
<
values_0_Arr
.
size
();
i
++)
{
JSONObject
values_0_Obj
=
values_0_Arr
.
getJSONObject
(
i
);
// 获取图片路径
String
imageUrl
=
values_0_Obj
.
getJSONArray
(
"images"
).
getJSONObject
(
0
).
getString
(
"url"
);
// 设置商品基本信息的图片
if
(
i
==
0
)
{
itemInfo
.
setPic
(
imageUrl
);
}
ProductProp
productPropColor
=
new
ProductProp
();
String
colorNo
=
values_0_Obj
.
getString
(
"code"
);
colorNoList
.
add
(
colorNo
);
productPropColor
.
setPropId
(
colorNo
);
productPropColor
.
setPropName
(
values_0_Obj
.
getString
(
"displayName"
));
productPropColor
.
setImage
(
imageUrl
);
propSet
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSet
);
}
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
///////////////////////// 获取商品尺码属性 ////////////////////////////////////////////////////////////////
// 取 options 的 1 位的 value 节点数组
List
<
String
>
sizeNoList
=
new
ArrayList
<>();
Set
<
ProductProp
>
sizePropSet
=
new
HashSet
<>();
JSONArray
values_1_Arr
=
detailsObj
.
getJSONArray
(
"options"
).
getJSONObject
(
1
).
getJSONArray
(
"values"
);
for
(
int
i
=
0
;
i
<
values_1_Arr
.
size
();
i
++)
{
JSONObject
values_1_Obj
=
values_1_Arr
.
getJSONObject
(
i
);
ProductProp
productPropSize
=
new
ProductProp
();
String
sizeNo
=
values_1_Obj
.
getString
(
"code"
);
productPropSize
.
setPropId
(
sizeNo
);
sizeNoList
.
add
(
sizeNo
);
productPropSize
.
setPropName
(
values_1_Obj
.
getString
(
"displayName"
));
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
}
///////////////////////// 获取商品尺码属性 END/////////////////////////////////////////////////////
for
(
String
colorNo
:
colorNoList
)
{
for
(
String
sizeNo
:
sizeNoList
)
{
// 设置 skuStr
String
skuStr
=
";"
+
colorNo
+
";"
+
sizeNo
+
";"
;
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
// 设置:可用库存值,Zara 未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
OriginalPrice
originalPrice
=
new
OriginalPrice
();
// 获取商品的原始价
String
fullPrice
=
detailsObj
.
getJSONObject
(
"salePrice"
).
getString
(
"amount"
);
// TODO 转换汇率,目前商品单位是人民币
fullPrice
=
exchangeRate
(
fullPrice
);
originalPrice
.
setPrice
(
fullPrice
);
productResponse
.
setPrice
(
fullPrice
);
productResponse
.
setSalePrice
(
fullPrice
+
"-"
+
fullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
//////////////////////////////////// 获取原始价 END//////////////////////////////////
}
}
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
LEVI
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/LilySpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
java.util.*
;
import
static
com
.
diaoyun
.
zion
.
master
.
util
.
spider
.
SpiderUtil
.
exchangeRate
;
/**
* Lily 爬虫数据解析
* @see com.diaoyun.zion.chinafrica.bis.impl.LilySpider
* @author 爱酱油不爱醋
*/
public
class
LilySpiderParse
{
/**
* 格式化返回数据
* TODO 未完成
* @param content 主要的商品内容
* @param pId 商品id
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
String
content
,
String
pId
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 解析为 Document 对象
Document
document
=
Jsoup
.
parse
(
content
);
// 获取商品的价格、颜色、标题、图片、尺码属性
String
fullPrice
=
document
.
select
(
"input[id=salePrice]"
).
attr
(
"value"
);
String
pColor
=
document
.
select
(
"input[id=colorDisPaly]"
).
attr
(
"value"
);
String
pTitle
=
document
.
select
(
"input[id=itemTitle]"
).
attr
(
"value"
);
String
pImg
=
document
.
select
(
"input[id=shoppingcartpic]"
).
attr
(
"value"
);
List
<
String
>
pSizeList
=
document
.
select
(
"div[class=overview product-size]"
)
.
select
(
"ul"
).
select
(
"li"
).
eachText
();
//////////////////////////////////// 获取商品基本信息 ////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
ZARA
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/MassimoDuttiSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
java.math.BigDecimal
;
import
java.util.*
;
/**
* MassimoDutti 爬虫数据解析
* @see com.diaoyun.zion.chinafrica.bis.impl.MassimoduttiSpider 数据爬虫
* @author 爱酱油不爱醋
*/
public
class
MassimoDuttiSpiderParse
{
/**
* 格式化返回数据
* @param dataMap 主要的 json 数据
* @param pId 商品链接的 id
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
JSONObject
dataMap
,
String
pId
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 商品基本信息
ItemInfo
itemInfo
=
new
ItemInfo
();
//////////////////////////////////// 获取商品基本信息 ////////////////////////////////////////////
itemInfo
.
setShopName
(
PlatformEnum
.
MASSIMODUTTI
.
getLabel
());
itemInfo
.
setShopUrl
(
"https://www.massimodutti.cn/cn/"
);
itemInfo
.
setItemId
(
pId
);
itemInfo
.
setTitle
(
dataMap
.
getString
(
"name"
));
//////////////////////////////////// 获取商品基本信息End(图片下取) ////////////////////////////////////////////
// 取 detail 节点对象
JSONObject
detailObj
=
dataMap
.
getJSONObject
(
"detail"
);
// 取 colors 节点数组
JSONArray
colorsArr
=
detailObj
.
getJSONArray
(
"colors"
);
for
(
int
i
=
0
;
i
<
colorsArr
.
size
();
i
++)
{
JSONObject
colorsObj
=
colorsArr
.
getJSONObject
(
i
);
// 取 image 节点对象
JSONObject
imageObj
=
colorsObj
.
getJSONObject
(
"image"
);
// 处理商品链接
String
imageUrl
=
"https://static.massimodutti.cn/3/photos"
+
imageObj
.
getString
(
"url"
)
+
"_2_5_16.jpg?t="
+
imageObj
.
getString
(
"timestamp"
);
if
(
i
==
0
)
{
itemInfo
.
setPic
(
imageUrl
);
}
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////////////////////
Set
<
ProductProp
>
propSetColor
=
new
HashSet
<>(
16
);
ProductProp
productPropColor
=
new
ProductProp
();
// 颜色id
String
colorNo
=
colorsObj
.
getString
(
"id"
);
productPropColor
.
setPropId
(
colorNo
);
// 颜色名
productPropColor
.
setPropName
(
colorsObj
.
getString
(
"name"
));
// 颜色图片
productPropColor
.
setImage
(
imageUrl
);
if
(
i
==
0
)
{
itemInfo
.
setPic
(
imageUrl
);
}
propSetColor
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSetColor
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSetColor
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSetColor
);
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
///////////////////////// 获取商品尺码属性 ////////////////////
// 取 sizes 节点对象
JSONArray
sizesArr
=
colorsObj
.
getJSONArray
(
"sizes"
);
for
(
int
j
=
0
;
j
<
sizesArr
.
size
();
j
++)
{
JSONObject
sizesObj
=
sizesArr
.
getJSONObject
(
j
);
Set
<
ProductProp
>
sizePropSetSize
=
new
HashSet
<>(
16
);
ProductProp
productPropSize
=
new
ProductProp
();
productPropSize
.
setPropName
(
sizesObj
.
getString
(
"name"
));
String
sizeNo
=
sizesObj
.
getString
(
"sku"
);
productPropSize
.
setPropId
(
sizeNo
);
sizePropSetSize
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSetSize
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSetSize
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSetSize
);
}
///////////////////////// 获取商品尺码属性 END////////////////////
// 库存 id
String
skuStr
=
";"
+
colorNo
+
";"
+
sizeNo
;
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
// 设置:可用库存值,Uniqlo 未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
OriginalPrice
originalPrice
=
new
OriginalPrice
();
// 获取商品的原始价
String
fullPrice
=
sizesObj
.
getString
(
"price"
);
BigDecimal
priceOld
=
new
BigDecimal
(
fullPrice
);
BigDecimal
div
=
new
BigDecimal
(
"100"
);
BigDecimal
priceNew
=
priceOld
.
divide
(
div
,
2
,
BigDecimal
.
ROUND_HALF_UP
);
// TODO 转换汇率,目前商品单位是人民币
fullPrice
=
SpiderUtil
.
exchangeRate
(
priceNew
.
toString
());
originalPrice
.
setPrice
(
fullPrice
);
productResponse
.
setPrice
(
fullPrice
);
productResponse
.
setSalePrice
(
fullPrice
+
"-"
+
fullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
//////////////////////////////////// 获取原始价 END//////////////////////////////////
}
}
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
MASSIMODUTTI
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/MocoSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
java.util.*
;
import
static
com
.
diaoyun
.
zion
.
master
.
util
.
spider
.
SpiderUtil
.
exchangeRate
;
/**
* MO&Co. 爬虫数据解析
* @see com.diaoyun.zion.chinafrica.bis.impl.MocoSpider
* @author 爱酱油不爱醋
*/
public
class
MocoSpiderParse
{
/**
* 格式化返回数据
* @param dataMap 主要的 Json 内容
* @param pId 截取的商品 id
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
JSONObject
dataMap
,
String
pId
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 取 productData 对象节点
JSONObject
productDataObj
=
dataMap
.
getJSONObject
(
"productData"
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
"MO&Co."
);
itemInfo
.
setShopUrl
(
"https://en.mo-co.com/"
);
itemInfo
.
setItemId
(
pId
);
itemInfo
.
setTitle
(
productDataObj
.
getString
(
"name"
));
//////////////////////////////////// 获取商品基本信息End(图片下取) ////////////////////////////////////////////
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////////////////////
// 取 baseOptions 对象数组的 1 位的 options 节点数组
JSONArray
options_1_Arr
=
productDataObj
.
getJSONArray
(
"baseOptions"
).
getJSONObject
(
1
).
getJSONArray
(
"options"
);
List
<
String
>
colorNoList
=
new
ArrayList
<>();
Set
<
ProductProp
>
propSet
=
new
HashSet
<>(
16
);
for
(
int
i
=
0
;
i
<
options_1_Arr
.
size
();
i
++)
{
JSONObject
options_1_Obj
=
options_1_Arr
.
getJSONObject
(
i
);
// 获取图片的路径
String
[]
spiltImg
=
options_1_Obj
.
getJSONArray
(
"variantOptionQualifiers"
)
.
getJSONObject
(
0
).
getJSONObject
(
"image"
).
getString
(
"url"
).
split
(
"_other_"
);
String
imageUrl
=
"https://mallimg.moco.com/"
+
pId
+
"_list_"
+
spiltImg
[
1
];
// 设置商品基本信息的图片
if
(
i
==
0
)
{
itemInfo
.
setPic
(
imageUrl
);
}
ProductProp
productPropColor
=
new
ProductProp
();
String
colorNo
=
options_1_Obj
.
getString
(
"epoColorCode"
);
colorNoList
.
add
(
colorNo
);
productPropColor
.
setPropId
(
colorNo
);
productPropColor
.
setPropName
(
options_1_Obj
.
getString
(
"epoColorName"
));
productPropColor
.
setImage
(
imageUrl
);
propSet
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSet
);
}
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
///////////////////////// 获取商品尺码属性 ////////////////////////////////////////////////////////////////
// 取 baseOptions 的 0 位的 options 节点数组
List
<
String
>
sizeNoList
=
new
ArrayList
<>();
Set
<
ProductProp
>
sizePropSet
=
new
HashSet
<>();
JSONArray
options_0_Arr
=
productDataObj
.
getJSONArray
(
"baseOptions"
).
getJSONObject
(
0
).
getJSONArray
(
"options"
);
for
(
int
i
=
0
;
i
<
options_0_Arr
.
size
();
i
++)
{
JSONObject
options_0_Obj
=
options_0_Arr
.
getJSONObject
(
i
);
ProductProp
productPropSize
=
new
ProductProp
();
String
sizeNo
=
options_0_Obj
.
getString
(
"epoSizeCode"
);
productPropSize
.
setPropId
(
sizeNo
);
sizeNoList
.
add
(
sizeNo
);
productPropSize
.
setPropName
(
options_0_Obj
.
getString
(
"epoSizeName"
)
+
options_0_Obj
.
getString
(
"sizeDescription"
));
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
///////////////////////// 获取商品尺码属性 END/////////////////////////////////////////////////////
}
for
(
String
colorNo
:
colorNoList
)
{
for
(
String
sizeNo
:
sizeNoList
)
{
// 设置 skuStr
String
skuStr
=
";"
+
colorNo
+
";"
+
sizeNo
+
";"
;
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
// 设置:可用库存值,Zara 未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
OriginalPrice
originalPrice
=
new
OriginalPrice
();
// 获取商品的原始价
String
fullPrice
=
productDataObj
.
getJSONObject
(
"price"
).
getString
(
"value"
);
// TODO 转换汇率,目前商品单位是人民币
fullPrice
=
exchangeRate
(
fullPrice
);
originalPrice
.
setPrice
(
fullPrice
);
productResponse
.
setPrice
(
fullPrice
);
productResponse
.
setSalePrice
(
fullPrice
+
"-"
+
fullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
//////////////////////////////////// 获取原始价 END//////////////////////////////////
}
}
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
MOCO
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/OchirlySpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
org.jsoup.nodes.Element
;
import
org.jsoup.select.Elements
;
import
java.util.*
;
/**
* Ochirly 数据爬虫
* @see com.diaoyun.zion.chinafrica.bis.impl.OchirlySpider
* @author 爱酱油不爱醋
*/
public
class
OchirlySpiderParse
{
/**
* 格式化返回数据
* @param content 主要的页面数据
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
String
content
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
Document
document
=
Jsoup
.
parse
(
content
);
// 获取标题
Elements
detailEle
=
document
.
select
(
"div[class=detail]"
).
select
(
"div[class=desc]"
);
String
pTitle
=
detailEle
.
select
(
"h5"
).
text
();
// 获取价格
Elements
priceEle
=
detailEle
.
select
(
"p[class=price]"
);
String
fullPrice
=
priceEle
.
attr
(
"data-list-price"
);
// 获取颜色id与图片
Elements
colorEle
=
document
.
select
(
"div[class=color]"
).
select
(
"ul[class=clearfix]"
);
List
<
String
>
imgUrlList
=
colorEle
.
select
(
"a"
).
eachAttr
(
"href"
);
List
<
String
>
pColorNoList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
imgUrlList
.
size
();
i
++)
{
String
hrefStr
=
imgUrlList
.
get
(
i
);
if
(
hrefStr
.
contains
(
"/p/mobile/"
))
{
String
[]
spilt
=
hrefStr
.
split
(
"/mobile/"
);
pColorNoList
.
add
(
spilt
[
1
].
replaceAll
(
".shtml"
,
""
));
}
else
{
pColorNoList
.
add
(
0
,
priceEle
.
attr
(
"data-sku"
));
}
}
List
<
String
>
pColorList
=
new
ArrayList
<>();
pColorList
.
addAll
(
pColorNoList
);
List
<
String
>
pImgList
=
colorEle
.
select
(
"img"
).
eachAttr
(
"src"
);
// 获取尺码
Elements
sizeEle
=
document
.
select
(
"div[class=size]"
).
select
(
"div[class=size_contain]"
).
select
(
"li"
);
List
<
String
>
pSizeList
=
new
ArrayList
<>();
List
<
String
>
pSizeNoList
=
new
ArrayList
<>();
for
(
Element
element
:
sizeEle
)
{
if
(
element
.
hasAttr
(
"data-size-id"
))
{
pSizeList
.
add
(
element
.
text
());
pSizeNoList
.
add
(
element
.
attr
(
"data-size-id"
));
}
}
//////////////////////////////////// 获取商品基本信息 ////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
PlatformEnum
.
OCHIRLY
.
getLabel
());
itemInfo
.
setShopUrl
(
"www.ochirly.com"
);
itemInfo
.
setItemId
(
detailEle
.
select
(
"p[class=price]"
).
attr
(
"data-sku"
));
itemInfo
.
setTitle
(
pTitle
);
itemInfo
.
setPic
(
pImgList
.
get
(
0
));
//////////////////////////////////// 获取商品基本信息End /////////////////////////
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////
for
(
int
i
=
0
;
i
<
pColorList
.
size
();
i
++)
{
Set
<
ProductProp
>
propSet
=
new
HashSet
<>(
16
);
ProductProp
productPropColor
=
new
ProductProp
();
productPropColor
.
setPropName
(
pColorList
.
get
(
i
));
productPropColor
.
setPropId
(
pColorNoList
.
get
(
i
));
productPropColor
.
setImage
(
pImgList
.
get
(
i
));
propSet
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSet
);
}
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
///////////////////////// 获取商品尺码属性 ////////////////////
for
(
int
i
=
0
;
i
<
pSizeList
.
size
();
i
++)
{
Set
<
ProductProp
>
sizePropSet
=
new
HashSet
<>();
ProductProp
productPropSize
=
new
ProductProp
();
productPropSize
.
setPropId
(
pSizeNoList
.
get
(
i
));
productPropSize
.
setPropName
(
pSizeList
.
get
(
i
));
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
}
///////////////////////// 获取商品尺码属性 END////////////////////
//////////////////////////////////// 获取库存与原始价 ////////////////////////////////////////////
for
(
String
pColorNo
:
pColorNoList
)
{
for
(
String
pSizeNo
:
pSizeNoList
)
{
// 设置库存id
String
skuStr
=
";"
+
pColorNo
+
";"
+
pSizeNo
+
";"
;
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
OriginalPrice
originalPrice
=
new
OriginalPrice
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
// 设置:可用库存值,未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
// TODO 转换汇率,目前商品单位是人民币
String
originalFullPrice
=
SpiderUtil
.
exchangeRate
(
fullPrice
);
originalPrice
.
setPrice
(
originalFullPrice
);
productResponse
.
setPrice
(
originalFullPrice
);
productResponse
.
setSalePrice
(
originalFullPrice
+
"-"
+
originalFullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
}
}
//////////////////////////////////// 获取库存与原始价 END///////////////////////////////
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
OCHIRLY
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/SpiderUtil.java
deleted
100644 → 0
浏览文件 @
eb49473c
差异被折叠。
点击展开。
src/main/java/com/diaoyun/zion/master/util/spider/UnderArmourSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
org.jsoup.select.Elements
;
import
java.util.*
;
/**
* UnderArmour 爬虫数据解析
* @see com.diaoyun.zion.chinafrica.bis.impl.UnderArmourSpider
* @author 爱酱油不爱醋
*/
public
class
UnderArmourSpiderParse
{
/**
* 格式化返回数据
* @param content 主要的页面数据
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
String
content
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 解析成 Document 对象
Document
document
=
Jsoup
.
parse
(
content
);
// 获取商品的标题、价格、颜色名称及id、尺码名称及id
String
pId
=
document
.
select
(
"span[class=e-color-show]"
).
text
();
String
pTitle
=
document
.
select
(
"h3[class=commo-name]"
).
text
();
String
fullPrice
=
document
.
select
(
"p[class=commo-price]"
).
text
().
replaceAll
(
"¥"
,
""
);
Elements
colorEle
=
document
.
select
(
"ul[class=color-choice float-clearfix e-color-choice]"
).
select
(
"li"
);
List
<
String
>
pColorList
=
colorEle
.
eachText
();
List
<
String
>
pColorNoList
=
colorEle
.
eachAttr
(
"itemcode"
);
Elements
sizeEle
=
document
.
select
(
"ul[class=size-choice float-clearfix e-size-choice]"
).
select
(
"li"
);
List
<
String
>
pSizeList
=
sizeEle
.
eachText
();
List
<
String
>
pSizeNoList
=
sizeEle
.
eachAttr
(
"skuid"
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
PlatformEnum
.
UNDERARMOUR
.
getLabel
());
itemInfo
.
setShopUrl
(
"https://www.adidas.com"
);
itemInfo
.
setItemId
(
pId
);
itemInfo
.
setTitle
(
pTitle
);
itemInfo
.
setPic
(
"https://underarmour.scene7.com/is/image/Underarmour/V5-"
+
pId
+
"_FC_Main"
);
//////////////////////////////////// 获取商品基本信息End /////////////////////////
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////
for
(
int
i
=
0
;
i
<
pColorList
.
size
();
i
++)
{
Set
<
ProductProp
>
propSet
=
new
HashSet
<>(
16
);
ProductProp
productPropColor
=
new
ProductProp
();
productPropColor
.
setPropName
(
pColorList
.
get
(
i
));
productPropColor
.
setPropId
(
pColorNoList
.
get
(
i
));
productPropColor
.
setImage
(
"https://underarmour.scene7.com/is/image/Underarmour/V5-"
+
pColorNoList
.
get
(
i
)
+
"_FC_Main"
);
propSet
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSet
);
}
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
///////////////////////// 获取商品尺码属性 ////////////////////
for
(
int
i
=
0
;
i
<
pSizeList
.
size
();
i
++)
{
Set
<
ProductProp
>
sizePropSet
=
new
HashSet
<>();
ProductProp
productPropSize
=
new
ProductProp
();
productPropSize
.
setPropId
(
pSizeNoList
.
get
(
i
));
productPropSize
.
setPropName
(
pSizeList
.
get
(
i
));
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
}
///////////////////////// 获取商品尺码属性 END////////////////////
//////////////////////////////////// 获取库存与原始价 ////////////////////////////////////////////
for
(
String
pColorNo
:
pColorNoList
)
{
for
(
String
pSizeNo
:
pSizeNoList
)
{
// 设置库存id
String
skuStr
=
";"
+
pColorNo
+
";"
+
pSizeNo
+
";"
;
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
OriginalPrice
originalPrice
=
new
OriginalPrice
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
// 设置:可用库存值,未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
// TODO 转换汇率,目前商品单位是人民币
String
originalFullPrice
=
SpiderUtil
.
exchangeRate
(
fullPrice
);
originalPrice
.
setPrice
(
originalFullPrice
);
productResponse
.
setPrice
(
originalFullPrice
);
productResponse
.
setSalePrice
(
originalFullPrice
+
"-"
+
originalFullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
}
}
//////////////////////////////////// 获取库存与原始价 END///////////////////////////////
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
UNDERARMOUR
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/UniqloSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
java.util.*
;
/**
* Uniqlo 数据爬虫
* @see com.diaoyun.zion.chinafrica.bis.impl.UniqloSpider
* @author 爱酱油不爱醋
*/
public
class
UniqloSpiderParse
{
/**
* 返回格式化数据
* @param dataMap 调用优衣库网页接口接收的主要商品数据
* @param pId 商品链接截取的商品id
* @return
*/
public
static
ProductResponse
formatProductResponse
(
JSONObject
dataMap
,
JSONObject
priceJson
,
String
pId
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 商品基本信息
ItemInfo
itemInfo
=
new
ItemInfo
();
// 取 summary 节点对象
JSONObject
summaryObj
=
dataMap
.
getJSONObject
(
"summary"
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////////////////////
itemInfo
.
setShopName
(
PlatformEnum
.
UNIQLO
.
getLabel
());
itemInfo
.
setShopUrl
(
"https://www.uniqlo.cn/product-detail.html"
);
itemInfo
.
setItemId
(
pId
);
itemInfo
.
setTitle
(
summaryObj
.
getString
(
"fullName"
));
//////////////////////////////////// 获取商品基本信息End(图片下取) ////////////////////////////////////////////
// 取 rows 节点数组
JSONArray
rowsArr
=
dataMap
.
getJSONArray
(
"rows"
);
for
(
int
i
=
0
;
i
<
rowsArr
.
size
();
i
++)
{
JSONObject
rowsObj
=
rowsArr
.
getJSONObject
(
i
);
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////////////////////
Set
<
ProductProp
>
propSetColor
=
new
HashSet
<>(
16
);
ProductProp
productPropColor
=
new
ProductProp
();
// 颜色id
String
colorNo
=
rowsObj
.
getString
(
"colorNo"
);
productPropColor
.
setPropId
(
colorNo
);
// 颜色名
String
colorName
=
rowsObj
.
getString
(
"style"
);
productPropColor
.
setPropName
(
colorName
);
// 颜色图片
String
imageUrl
=
"https://www.uniqlo.cn/hmall/test/"
+
pId
+
"/sku/561/"
+
colorNo
+
".jpg"
;
productPropColor
.
setImage
(
imageUrl
);
if
(
i
==
0
)
{
itemInfo
.
setPic
(
imageUrl
);
}
propSetColor
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSetColor
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSetColor
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSetColor
);
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
///////////////////////// 获取商品尺码属性 ////////////////////
Set
<
ProductProp
>
sizePropSetSize
=
new
HashSet
<>();
ProductProp
productPropSize
=
new
ProductProp
();
String
size
=
rowsObj
.
getString
(
"sizeText"
);
productPropSize
.
setPropName
(
size
);
String
sizeNo
=
rowsObj
.
getString
(
"skuId"
);
productPropSize
.
setPropId
(
sizeNo
);
sizePropSetSize
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSetSize
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSetSize
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSetSize
);
}
///////////////////////// 获取商品尺码属性 END////////////////////
String
skuStr
=
";"
+
colorNo
+
";"
+
sizeNo
+
";"
;
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
// 设置:可用库存值,Uniqlo 未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
OriginalPrice
originalPrice
=
new
OriginalPrice
();
// 获取商品的原始价
String
fullPrice
=
summaryObj
.
getString
(
"originPrice"
);
// TODO 转换汇率,目前商品单位是人民币
fullPrice
=
SpiderUtil
.
exchangeRate
(
fullPrice
);
originalPrice
.
setPrice
(
fullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
//////////////////////////////////// 获取原始价 END//////////////////////////////////
//////////////////////////////////// 获取促销价 //////////////////////////////////
// 取 summary 节点对象
JSONObject
summaryPriceObj
=
priceJson
.
getJSONArray
(
"resp"
).
getJSONObject
(
0
).
getJSONObject
(
"summary"
);
ProductPromotion
productPromotion
=
new
ProductPromotion
();
// 获取商品的促销价
String
promotionPrice
=
summaryPriceObj
.
getString
(
"maxPrice"
);
// TODO 转换汇率,目前商品单位是人民币
promotionPrice
=
SpiderUtil
.
exchangeRate
(
promotionPrice
);
productPromotion
.
setSkuStr
(
skuStr
);
productPromotion
.
setPrice
(
promotionPrice
);
productResponse
.
setPrice
(
promotionPrice
);
productResponse
.
setSalePrice
(
promotionPrice
+
"-"
+
fullPrice
);
promotionList
.
add
(
productPromotion
);
//////////////////////////////////// 获取促销价 END//////////////////////////////////
}
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setPromotionFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
UNIQLO
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/UrbanRevivoSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
java.util.*
;
import
static
com
.
diaoyun
.
zion
.
master
.
util
.
spider
.
SpiderUtil
.
exchangeRate
;
/**
* UrbanRevivo 爬虫数据解析
* @see com.diaoyun.zion.chinafrica.bis.impl.UrbanRevivoSpider
* @author 爱酱油不爱醋
*/
public
class
UrbanRevivoSpiderParse
{
/**
* 格式化返回数据
* @param dataMap 主要的 json 数据
* @param pId 截取的商品 id
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
JSONObject
dataMap
,
String
pId
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 取 data 数据节点
JSONObject
dataObj
=
dataMap
.
getJSONObject
(
"data"
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
PlatformEnum
.
URBANREVIVO
.
getLabel
());
itemInfo
.
setShopUrl
(
"http://www.ur.cn/index.html"
);
itemInfo
.
setItemId
(
pId
);
itemInfo
.
setTitle
(
dataObj
.
getString
(
"name"
));
itemInfo
.
setPic
(
"https://gw-img.ur.com.cn//"
+
dataObj
.
getString
(
"image"
));
//////////////////////////////////// 获取商品基本信息End////////////////////////////////////////////
// 取 colors 节点数组
JSONArray
colorsArr
=
dataObj
.
getJSONArray
(
"colors"
);
for
(
int
i
=
0
;
i
<
colorsArr
.
size
();
i
++)
{
JSONObject
colorsObj
=
colorsArr
.
getJSONObject
(
i
);
// 获取图片路径
String
imgUrl
=
"https://gw-img.ur.com.cn//"
+
colorsObj
.
getString
(
"image"
);
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////////////////////
Set
<
ProductProp
>
propSet
=
new
HashSet
<>(
16
);
ProductProp
productPropColor
=
new
ProductProp
();
String
colorNo
=
colorsObj
.
getString
(
"productColorId"
);
productPropColor
.
setPropId
(
colorNo
);
productPropColor
.
setPropName
(
colorsObj
.
getString
(
"aliasName"
));
productPropColor
.
setImage
(
imgUrl
);
propSet
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSet
);
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
// 取 skus 节点数组
JSONArray
skusArr
=
colorsObj
.
getJSONArray
(
"skus"
);
for
(
int
j
=
0
;
j
<
skusArr
.
size
();
j
++)
{
JSONObject
skusObj
=
skusArr
.
getJSONObject
(
j
);
///////////////////////// 获取商品尺码属性 ////////////////////
Set
<
ProductProp
>
sizePropSet
=
new
HashSet
<>();
ProductProp
productPropSize
=
new
ProductProp
();
String
sizeNo
=
skusObj
.
getString
(
"barCode"
);
productPropSize
.
setPropId
(
sizeNo
);
productPropSize
.
setPropName
(
skusObj
.
getString
(
"sizeAlias"
));
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
///////////////////////// 获取商品尺码属性 END////////////////////
// 设置库存id
String
skuStr
=
";"
+
colorNo
+
";"
+
sizeNo
+
";"
;
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
// 设置:可用库存值,未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
OriginalPrice
originalPrice
=
new
OriginalPrice
();
// 获取商品的原始价
String
fullPrice
=
dataObj
.
getString
(
"tagPrice"
);
// TODO 转换汇率,目前商品单位是人民币
fullPrice
=
exchangeRate
(
fullPrice
);
originalPrice
.
setPrice
(
fullPrice
);
productResponse
.
setPrice
(
fullPrice
);
productResponse
.
setSalePrice
(
fullPrice
+
"-"
+
fullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
//////////////////////////////////// 获取原始价 END//////////////////////////////////
}
}
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
URBANREVIVO
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/VansSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
org.jsoup.select.Elements
;
import
java.util.*
;
import
java.util.regex.Pattern
;
/**
* Vans(范斯) 爬虫数据解析
* @see com.diaoyun.zion.chinafrica.bis.impl.VansSpider
* @author 爱酱油不爱醋
*/
public
class
VansSpiderParse
{
/**
* 格式化返回数据
* @param content 主要的页面数据
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
String
content
,
String
pId
,
String
pTitle
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
// 解析成 Document 对象
Document
document
=
Jsoup
.
parse
(
content
);
Elements
colorUrlEle
=
document
.
select
(
"div[class=pro-color]"
).
select
(
"a"
);
// 价格
String
fullPrice
=
Pattern
.
compile
(
"[^0-9]"
).
matcher
(
document
.
select
(
"span[id=spec_price]"
).
text
()).
replaceAll
(
""
).
trim
();
// 颜色Id
List
<
String
>
colorNoList
=
colorUrlEle
.
eachAttr
(
"data-product-id"
);
// 颜色名称
List
<
String
>
colorList
=
colorUrlEle
.
eachText
();
// 颜色图片
List
<
String
>
imageList
=
colorUrlEle
.
select
(
"img"
).
eachAttr
(
"src"
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
PlatformEnum
.
VANS
.
getLabel
());
itemInfo
.
setShopUrl
(
"https://www.vans.com"
);
itemInfo
.
setItemId
(
pId
);
itemInfo
.
setTitle
(
pTitle
);
itemInfo
.
setPic
(
imageList
.
get
(
0
));
//////////////////////////////////// 获取商品基本信息End /////////////////////////
// //////////////////////////////////// 获取商品颜色属性 ////////////////////////////
// for (int i = 0; i < pColorList.size(); i++) {
// Set<ProductProp> propSet = new HashSet<>(16);
// ProductProp productPropColor = new ProductProp();
// productPropColor.setPropName(pColorList.get(i));
// productPropColor.setPropId(pColorNoList.get(i));
// productPropColor.setImage("https://underarmour.scene7.com/is/image/Underarmour/V5-" + pColorNoList.get(i) + "_FC_Main");
// propSet.add(productPropColor);
// if (productPropSet.get("颜色") == null) {
// productPropSet.put("颜色", propSet);
// } else {
// Set<ProductProp> oldPropSet = productPropSet.get("颜色");
// propSet.addAll(oldPropSet);
// productPropSet.put("颜色", propSet);
// }
// }
// //////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
//
// ///////////////////////// 获取商品尺码属性 ////////////////////
// for (int i = 0; i < pSizeList.size(); i++) {
// Set<ProductProp> sizePropSet = new HashSet<>();
// ProductProp productPropSize = new ProductProp();
// productPropSize.setPropId(pSizeNoList.get(i));
// productPropSize.setPropName(pSizeList.get(i));
// sizePropSet.add(productPropSize);
// if (productPropSet.get("尺码") == null) {
// productPropSet.put("尺码", sizePropSet);
// } else {
// Set<ProductProp> oldPropSet = productPropSet.get("尺码");
// sizePropSet.addAll(oldPropSet);
// productPropSet.put("尺码", sizePropSet);
// }
//
// }
// ///////////////////////// 获取商品尺码属性 END////////////////////
//
// //////////////////////////////////// 获取库存与原始价 ////////////////////////////////////////////
// for (String pColorNo : pColorNoList) {
// for (String pSizeNo : pSizeNoList) {
// // 设置库存id
// String skuStr = ";" + pColorNo + ";" + pSizeNo + ";";
// // 设置:商品包含库存信息
// productResponse.setStockFlag(true);
// List<ProductSkuStock> productSkuStockList = dynStock.getProductSkuStockList();
// ProductSkuStock productSkuStock = new ProductSkuStock();
// OriginalPrice originalPrice = new OriginalPrice();
// if (productSkuStockList == null) {
// productSkuStockList = new ArrayList<>();
// }
//
// // 设置:可用库存值,未有可用的库存数据
// productSkuStock.setSellableQuantity(999);
// // 设置:库存对应的id
// productSkuStock.setSkuStr(skuStr);
// productSkuStockList.add(productSkuStock);
// dynStock.setProductSkuStockList(productSkuStockList);
//
// // TODO 转换汇率,目前商品单位是人民币
// String originalFullPrice = SpiderUtil.exchangeRate(fullPrice);
// originalPrice.setPrice(originalFullPrice);
// productResponse.setPrice(originalFullPrice);
// productResponse.setSalePrice(originalFullPrice + "-" + originalFullPrice);
// originalPrice.setSkuStr(skuStr);
// originalPriceList.add(originalPrice);
// }
// }
// //////////////////////////////////// 获取库存与原始价 END///////////////////////////////
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
UNDERARMOUR
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
src/main/java/com/diaoyun/zion/master/util/spider/ZaraSpiderParse.java
deleted
100644 → 0
浏览文件 @
eb49473c
package
com
.
diaoyun
.
zion
.
master
.
util
.
spider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.*
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
java.math.BigDecimal
;
import
java.util.*
;
import
static
com
.
diaoyun
.
zion
.
master
.
util
.
spider
.
SpiderUtil
.
exchangeRate
;
/**
* Zara 爬虫数据解析
* @see com.diaoyun.zion.chinafrica.bis.impl.ZaraSpider
* @author 爱酱油不爱醋
*/
public
class
ZaraSpiderParse
{
/**
* 获取主要数据
* @param content 商品的 HTML 页面
* @return 截取后的主要数据
*/
public
static
JSONObject
getJsonData
(
String
content
)
{
int
labelHeadIndex
=
content
.
indexOf
(
"dataLayer"
);
int
labelTailIndex
=
content
.
lastIndexOf
(
";window.zara.viewPayload"
);
String
abv
=
content
.
substring
(
labelHeadIndex
,
labelTailIndex
).
replace
(
"dataLayer = "
,
""
);
JSONObject
dataMap
=
JSONObject
.
fromObject
(
abv
);
return
dataMap
;
}
/**
* 格式化返回数据
* @param dataMap 主要的 json 数据
* @return 格式化后的数据
*/
public
static
ProductResponse
formatProductResponse
(
JSONObject
dataMap
)
{
// 声明封装类
ProductResponse
productResponse
=
new
ProductResponse
();
// 属性:Zara 的商品属性有颜色、尺码
Map
<
String
,
Set
<
ProductProp
>>
productPropSet
=
new
HashMap
<>(
16
);
// 原始价
List
<
OriginalPrice
>
originalPriceList
=
new
ArrayList
<>();
// 促销价格
List
<
ProductPromotion
>
promotionList
=
new
ArrayList
<>();
// 库存
DynStock
dynStock
=
new
DynStock
();
// 其实数据没有包含确切的库存数,这里默认给足量的库存
dynStock
.
setSellableQuantity
(
9999
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////////////////////
ItemInfo
itemInfo
=
new
ItemInfo
();
itemInfo
.
setShopName
(
"Zara"
);
itemInfo
.
setShopUrl
(
dataMap
.
getString
(
"backUrl"
));
JSONObject
productObj
=
dataMap
.
getJSONObject
(
"product"
);
itemInfo
.
setItemId
(
productObj
.
getString
(
"id"
));
itemInfo
.
setTitle
(
productObj
.
getString
(
"name"
));
//////////////////////////////////// 获取商品基本信息End(图片下取) ////////////////////////////////////////////
// 取 colors 节点数组
JSONArray
colorsArr
=
productObj
.
getJSONObject
(
"detail"
).
getJSONArray
(
"colors"
);
for
(
int
i
=
0
;
i
<
colorsArr
.
size
();
i
++)
{
JSONObject
colorsObj
=
colorsArr
.
getJSONObject
(
i
);
// 取 detailImagesArr 节点数组第一个对象
JSONObject
detailImagesObj_0
=
colorsObj
.
getJSONArray
(
"detailImages"
).
getJSONObject
(
0
);
// 处理图片 参考路径:http://static.zara.cn/photos///2019/I/0/1/p/0858/457/800/17/w/1920/0858457800_1_1_1.jpg?ts=1570720340221
String
imageUrl
=
"http://static.zara.cn/photos//"
+
detailImagesObj_0
.
getString
(
"path"
)
+
"w/1920/"
+
detailImagesObj_0
.
getString
(
"name"
)
+
"_1.jpg?ts="
+
detailImagesObj_0
.
getString
(
"timestamp"
);
if
(
i
==
0
)
{
// 商品基本信息--设置:图片
itemInfo
.
setPic
(
imageUrl
);
}
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////////////////////
Set
<
ProductProp
>
propSet
=
new
HashSet
<>(
16
);
ProductProp
productPropColor
=
new
ProductProp
();
// 颜色描述
productPropColor
.
setPropId
(
colorsObj
.
getString
(
"productId"
));
productPropColor
.
setPropName
(
colorsObj
.
getString
(
"name"
));
productPropColor
.
setImage
(
imageUrl
);
propSet
.
add
(
productPropColor
);
if
(
productPropSet
.
get
(
"颜色"
)
==
null
)
{
productPropSet
.
put
(
"颜色"
,
propSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"颜色"
);
propSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"颜色"
,
propSet
);
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
// 取 sizes 节点数组
JSONArray
sizesArr
=
colorsArr
.
getJSONObject
(
i
).
getJSONArray
(
"sizes"
);
for
(
int
j
=
0
;
j
<
sizesArr
.
size
();
j
++)
{
JSONObject
sizesObj
=
sizesArr
.
getJSONObject
(
j
);
// 库存对应的id(Zara 中以颜色id + 尺码id)
String
skuStr
=
";"
+
colorsObj
.
getString
(
"productId"
)
+
";"
+
sizesObj
.
getString
(
"sku"
)
+
";"
;
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// 设置:商品包含库存信息
productResponse
.
setStockFlag
(
true
);
List
<
ProductSkuStock
>
productSkuStockList
=
dynStock
.
getProductSkuStockList
();
if
(
productSkuStockList
==
null
)
{
productSkuStockList
=
new
ArrayList
<>();
}
ProductSkuStock
productSkuStock
=
new
ProductSkuStock
();
// 设置:可用库存值,Zara 未有可用的库存数据
productSkuStock
.
setSellableQuantity
(
999
);
// 设置:库存对应的id
productSkuStock
.
setSkuStr
(
skuStr
);
productSkuStockList
.
add
(
productSkuStock
);
dynStock
.
setProductSkuStockList
(
productSkuStockList
);
//////////////////////////////////// 获取库存 END/////////////////////////////////////////
//////////////////////////////////// 获取原始价 //////////////////////////////////
OriginalPrice
originalPrice
=
new
OriginalPrice
();
// 获取商品的原始价
String
fullPrice
=
sizesObj
.
getString
(
"price"
);
BigDecimal
priceOld
=
new
BigDecimal
(
fullPrice
);
BigDecimal
div
=
new
BigDecimal
(
"100"
);
BigDecimal
priceNew
=
priceOld
.
divide
(
div
,
2
,
BigDecimal
.
ROUND_DOWN
);
// TODO 转换汇率,目前商品单位是人民币
fullPrice
=
exchangeRate
(
priceNew
.
toString
());
originalPrice
.
setPrice
(
fullPrice
);
productResponse
.
setPrice
(
fullPrice
);
productResponse
.
setSalePrice
(
fullPrice
+
"-"
+
fullPrice
);
originalPrice
.
setSkuStr
(
skuStr
);
originalPriceList
.
add
(
originalPrice
);
//////////////////////////////////// 获取原始价 END//////////////////////////////////
///////////////////////// 获取商品尺码属性 ////////////////////
Set
<
ProductProp
>
sizePropSet
=
new
HashSet
<>();
ProductProp
productPropSize
=
new
ProductProp
();
String
size
=
sizesObj
.
getString
(
"name"
);
productPropSize
.
setPropId
(
sizesObj
.
getString
(
"sku"
));
productPropSize
.
setPropName
(
size
);
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
else
{
Set
<
ProductProp
>
oldPropSet
=
productPropSet
.
get
(
"尺码"
);
sizePropSet
.
addAll
(
oldPropSet
);
productPropSet
.
put
(
"尺码"
,
sizePropSet
);
}
///////////////////////// 获取商品尺码属性 END////////////////////
}
}
// 按照一下顺序进行 json 数据的填充
productResponse
.
setPropFlag
(
true
);
productResponse
.
setProductPropSet
(
productPropSet
);
productResponse
.
setPlatform
(
PlatformEnum
.
ZARA
.
getValue
());
productResponse
.
setPromotionList
(
promotionList
);
productResponse
.
setOriginalPriceList
(
originalPriceList
);
productResponse
.
setItemInfo
(
itemInfo
);
productResponse
.
setDynStock
(
dynStock
);
return
productResponse
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论