Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
63f45184
提交
63f45184
authored
11月 29, 2019
作者:
梁业锦
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改adidas爬虫的BUG
上级
c1cfd468
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
25 行删除
+19
-25
AdidasSpider.java
...va/com/diaoyun/zion/chinafrica/bis/impl/AdidasSpider.java
+19
-25
没有找到文件。
src/main/java/com/diaoyun/zion/chinafrica/bis/impl/AdidasSpider.java
浏览文件 @
63f45184
...
...
@@ -8,6 +8,8 @@ import com.diaoyun.zion.master.util.TranslateHelper;
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
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
...
...
@@ -33,6 +35,7 @@ public class AdidasSpider implements IItemSpider {
/**
* Adidas 数据爬虫
*
* @param targetUrl 接收的商品详情路径
* @return 格式化与翻译后的 Json 数据
*/
...
...
@@ -55,6 +58,7 @@ public class AdidasSpider implements IItemSpider {
/**
* 格式化返回数据
*
* @param content 主要的页面数据
* @return 格式化后的数据
*/
...
...
@@ -81,38 +85,29 @@ public class AdidasSpider implements IItemSpider {
// 解析为 Document 对象
Document
document
=
Jsoup
.
parse
(
content
);
// 获取颜色(型号)
List
<
String
>
colorNoList
=
document
.
select
(
"div[class=pdp-color events-color-close]"
)
.
select
(
"ul"
).
select
(
"li"
).
eachAttr
(
"code"
);
// 获取价格
String
fullPrice
=
document
.
select
(
"input[id=salePrice]"
).
attr
(
"value"
);
String
originalFullPrice
=
exchangeRate
(
fullPrice
);
// 获取尺码
List
<
String
>
pSizeList
=
document
.
select
(
"div[class=overview product-size]"
)
.
select
(
"ul"
).
select
(
"li"
).
eachText
();
String
originalFullPrice
=
document
.
select
(
"input[id=salePrice]"
).
attr
(
"value"
);
originalFullPrice
=
exchangeRate
(
originalFullPrice
);
//////////////////////////////////// 获取商品基本信息 ////////////////////////////
itemInfo
.
setShopName
(
"Adidas"
);
itemInfo
.
setShopUrl
(
"https://www.adidas.com"
);
itemInfo
.
setItemId
(
pId
);
itemInfo
.
setTitle
(
document
.
select
(
"input[id=itemTitle]"
).
attr
(
"value"
));
String
colorNo
=
document
.
select
(
"input[id=itemCode]"
).
attr
(
"value"
);
itemInfo
.
setTitle
(
colorNo
);
itemInfo
.
setPic
(
document
.
select
(
"input[id=shoppingcartpic]"
).
attr
(
"value"
));
//////////////////////////////////// 获取商品基本信息End /////////////////////////
//////////////////////////////////// 获取商品颜色属性 ////////////////////////////
for
(
String
colorNo
:
colorNoList
)
{
Elements
colorEle
=
document
.
select
(
"ul[id=itemColor]"
).
select
(
"li"
);
String
targetUrl
=
"https://www.adidas.com.cn/item/othercolor?itemCode="
+
pId
;
String
colorContent
=
HttpClientUtil
.
getContentByUrl
(
targetUrl
,
PlatformEnum
.
ADIDAS
.
getValue
());
for
(
Element
colorElement
:
colorEle
)
{
Document
colorDoc
=
Jsoup
.
parse
(
colorContent
);
String
color
=
colorDoc
.
select
(
"input[id=colorDisPaly]"
).
attr
(
"value"
);
String
imgUrl
=
colorDoc
.
select
(
"input[id=shoppingcartpic]"
).
attr
(
"value"
);
String
color
=
colorElement
.
attr
(
"code"
);
String
imgUrl
=
colorElement
.
select
(
"img"
).
attr
(
"lazy-src"
);
ProductProp
productPropColor
=
new
ProductProp
();
productPropColor
.
setPropId
(
color
No
);
productPropColor
.
setPropId
(
color
);
productPropColor
.
setPropName
(
color
);
productPropColor
.
setImage
(
imgUrl
);
propSet
.
add
(
productPropColor
);
...
...
@@ -125,14 +120,13 @@ public class AdidasSpider implements IItemSpider {
}
//////////////////////////////////// 获取商品颜色属性 END ////////////////////////////////////////////
for
(
int
i
=
0
;
i
<
pSizeList
.
size
();
i
++)
{
Elements
sizeEles
=
document
.
select
(
"div[class=overview product-size]"
).
select
(
"li"
);
for
(
Element
sizeEle
:
sizeEles
)
{
String
size
=
sizeEle
.
attr
(
"dispalySize"
);
///////////////////////// 获取商品尺码属性 ////////////////////
String
sizeNo
=
pSizeList
.
get
(
i
);
String
size
=
sizeNo
;
ProductProp
productPropSize
=
new
ProductProp
();
productPropSize
.
setPropId
(
size
No
);
productPropSize
.
setPropId
(
size
);
productPropSize
.
setPropName
(
size
);
sizePropSet
.
add
(
productPropSize
);
if
(
productPropSet
.
get
(
"尺码"
)
==
null
)
{
...
...
@@ -145,7 +139,7 @@ public class AdidasSpider implements IItemSpider {
///////////////////////// 获取商品尺码属性 END////////////////////
// 库存对应的id(颜色id + 尺码id)
String
skuStr
=
";"
+
colorNo
+
";"
+
pSizeList
.
get
(
i
)
+
";"
;
String
skuStr
=
";"
+
colorNo
+
";"
+
size
+
";"
;
//////////////////////////////////// 获取库存 ////////////////////////////////////////////
// 设置:商品包含库存信息
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论