Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
9f0148fb
提交
9f0148fb
authored
10月 17, 2019
作者:
张光耀
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加了,Zara,代做
上级
0818a63b
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
31 行增加
和
6 行删除
+31
-6
ZaraSpider.java
...java/com/diaoyun/zion/chinafrica/bis/impl/ZaraSpider.java
+12
-6
SpiderServiceImpl.java
...aoyun/zion/chinafrica/service/impl/SpiderServiceImpl.java
+6
-0
JsoupUtil.java
src/main/java/com/diaoyun/zion/master/util/JsoupUtil.java
+13
-0
没有找到文件。
src/main/java/com/diaoyun/zion/chinafrica/bis/impl/ZaraSpider.java
浏览文件 @
9f0148fb
...
@@ -2,7 +2,11 @@ package com.diaoyun.zion.chinafrica.bis.impl;
...
@@ -2,7 +2,11 @@ package com.diaoyun.zion.chinafrica.bis.impl;
import
com.diaoyun.zion.chinafrica.bis.IItemSpider
;
import
com.diaoyun.zion.chinafrica.bis.IItemSpider
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.vo.ProductResponse
;
import
com.diaoyun.zion.master.util.HttpClientUtil
;
import
com.diaoyun.zion.master.util.HttpClientUtil
;
import
com.diaoyun.zion.master.util.JsoupUtil
;
import
com.diaoyun.zion.master.util.SpiderUtil
;
import
com.diaoyun.zion.master.util.TranslateHelper
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
net.sf.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -29,14 +33,16 @@ public class ZaraSpider implements IItemSpider {
...
@@ -29,14 +33,16 @@ public class ZaraSpider implements IItemSpider {
@Override
@Override
public
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
public
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
JSONObject
resultObj
;
// 获取url中的网页内容
// 获取url中的网页内容
String
content
=
HttpClientUtil
.
getContentByUrl
(
targetUrl
,
PlatformEnum
.
ZARA
.
getValue
());
String
content
=
HttpClientUtil
.
getContentByUrl
(
targetUrl
,
PlatformEnum
.
ZARA
.
getValue
());
// 截取主要的 Json 内容
// 截取主要的 Json 内容
String
jsonDataStr
=
getDataJson
(
content
,
"dataLayer"
,
";window.zara.viewPayload"
)
resultObj
=
JsoupUtil
.
getZara
(
content
);
.
replace
(
"dataLayer = "
,
""
);
ProductResponse
productResponse
=
SpiderUtil
.
formatNikeProductResponse
(
resultObj
);
// 转换为 Json 格式
resultObj
=
JSONObject
.
fromObject
(
productResponse
);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
jsonDataStr
);
//翻译
return
jsonObject
;
TranslateHelper
.
translateProductResponse
(
resultObj
);
return
resultObj
;
}
}
/**
/**
...
@@ -49,7 +55,7 @@ public class ZaraSpider implements IItemSpider {
...
@@ -49,7 +55,7 @@ public class ZaraSpider implements IItemSpider {
private
static
String
getDataJson
(
String
jsonStr
,
String
startStr
,
String
lastStr
)
{
private
static
String
getDataJson
(
String
jsonStr
,
String
startStr
,
String
lastStr
)
{
int
startIndex
=
jsonStr
.
indexOf
(
startStr
);
int
startIndex
=
jsonStr
.
indexOf
(
startStr
);
int
lastIndex
=
jsonStr
.
lastIndexOf
(
lastStr
);
int
lastIndex
=
jsonStr
.
lastIndexOf
(
lastStr
);
return
jsonStr
.
substring
(
startIndex
,
lastIndex
);
return
jsonStr
.
substring
(
startIndex
,
lastIndex
);
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
,
URISyntaxException
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
URISyntaxException
{
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/impl/SpiderServiceImpl.java
浏览文件 @
9f0148fb
...
@@ -51,6 +51,12 @@ public class SpiderServiceImpl implements SpiderService {
...
@@ -51,6 +51,12 @@ public class SpiderServiceImpl implements SpiderService {
platformEnum
=
PlatformEnum
.
GAP
;
platformEnum
=
PlatformEnum
.
GAP
;
}
else
if
(
targetUrl
.
contains
(
"www.nike.com/cn/t/"
))
{
}
else
if
(
targetUrl
.
contains
(
"www.nike.com/cn/t/"
))
{
platformEnum
=
PlatformEnum
.
NIKE
;
platformEnum
=
PlatformEnum
.
NIKE
;
}
else
if
(
targetUrl
.
contains
(
"www.afri-eshop.com"
)&&
targetUrl
.
contains
(
"/products/"
))
{
platformEnum
=
PlatformEnum
.
AfriEshop
;
}
else
if
(
targetUrl
.
contains
(
"zara.cn"
))
{
platformEnum
=
platformEnum
.
ZARA
;
}
else
if
(
targetUrl
.
contains
(
"uniqlo.cn/product-detail.html"
))
{
platformEnum
=
platformEnum
.
UNIQLO
;
}
}
return
platformEnum
;
return
platformEnum
;
}
}
...
...
src/main/java/com/diaoyun/zion/master/util/JsoupUtil.java
浏览文件 @
9f0148fb
...
@@ -224,6 +224,19 @@ public class JsoupUtil {
...
@@ -224,6 +224,19 @@ public class JsoupUtil {
return
dataMap
;
return
dataMap
;
}
}
/**
*
* @param content
* @return
*/
public
static
JSONObject
getZara
(
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
;
}
/**
/**
* 根据script id获取内容
* 根据script id获取内容
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论