Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
50becc76
提交
50becc76
authored
9月 29, 2019
作者:
zhengfg
提交者:
张光耀
9月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
爬虫提交
上级
591f8b9e
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
193 行增加
和
2 行删除
+193
-2
GapSpider.java
.../java/com/diaoyun/zion/chinafrica/bis/impl/GapSpider.java
+25
-0
TbItemSpider.java
...va/com/diaoyun/zion/chinafrica/bis/impl/TbItemSpider.java
+0
-2
UniqloSpider.java
...va/com/diaoyun/zion/chinafrica/bis/impl/UniqloSpider.java
+39
-0
ZaraSpider.java
...java/com/diaoyun/zion/chinafrica/bis/impl/ZaraSpider.java
+105
-0
PlatformEnum.java
.../java/com/diaoyun/zion/chinafrica/enums/PlatformEnum.java
+3
-0
ItemSpiderFactory.java
...om/diaoyun/zion/chinafrica/factory/ItemSpiderFactory.java
+19
-0
JsoupUtil.java
src/main/java/com/diaoyun/zion/master/util/JsoupUtil.java
+2
-0
没有找到文件。
src/main/java/com/diaoyun/zion/chinafrica/bis/impl/GapSpider.java
0 → 100644
浏览文件 @
50becc76
package
com
.
diaoyun
.
zion
.
chinafrica
.
bis
.
impl
;
import
com.diaoyun.zion.chinafrica.bis.IItemSpider
;
import
net.sf.json.JSONObject
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
/**
* TODO Gap美国休闲品牌数据爬虫
*
* 分析:产品数据在 F12 的 Network 中的 "spu.do" 文件中,该文件返回产品的 Json 数据
*/
@Component
(
"gapSpider"
)
public
class
GapSpider
implements
IItemSpider
{
@Override
public
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
return
null
;
}
}
src/main/java/com/diaoyun/zion/chinafrica/bis/impl/TbItemSpider.java
浏览文件 @
50becc76
...
@@ -94,8 +94,6 @@ public class TbItemSpider implements IItemSpider {
...
@@ -94,8 +94,6 @@ public class TbItemSpider implements IItemSpider {
return
returnJson
;
return
returnJson
;
}
}
/**
/**
* 翻译规格属性
* 翻译规格属性
* @param propMap 规格属性MAP
* @param propMap 规格属性MAP
...
...
src/main/java/com/diaoyun/zion/chinafrica/bis/impl/UniqloSpider.java
0 → 100644
浏览文件 @
50becc76
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.master.util.HttpClientUtil
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.apache.http.Consts
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.utils.URLEncodedUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.net.MalformedURLException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
java.nio.charset.Charset
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
/**
* TODO 优衣库数据爬虫
*/
@Component
(
"uniqloSpider"
)
public
class
UniqloSpider
implements
IItemSpider
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
UniqloSpider
.
class
);
@Override
public
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
return
null
;
}
}
src/main/java/com/diaoyun/zion/chinafrica/bis/impl/ZaraSpider.java
0 → 100644
浏览文件 @
50becc76
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.master.util.HttpClientUtil
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
/**
* Zara西班牙时尚品牌数据爬虫
*/
@Component
(
"zaraSpider"
)
public
class
ZaraSpider
implements
IItemSpider
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
TmItemSpider
.
class
);
//西班牙时尚品牌数据爬虫
private
static
final
String
zaraUrl
=
"https://www.zara.cn/cn/zh/"
;
@Override
public
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
// 获取url中的网页内容
String
content
=
HttpClientUtil
.
getContentByUrl
(
targetUrl
,
PlatformEnum
.
ZARA
.
getValue
());
// 截取主要的 Json 内容
String
jsonDataStr
=
getDataJson
(
content
,
"dataLayer"
,
";window.zara.viewPayload"
)
.
replace
(
"dataLayer = "
,
""
);
// 转换为 Json 格式
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
jsonDataStr
);
return
jsonObject
;
}
/**
* 根据首位字符串内容进行截取
* @param jsonStr
* @param startStr 起始字符串
* @param lastStr 结尾字符串(不包含)
* @return
*/
private
static
String
getDataJson
(
String
jsonStr
,
String
startStr
,
String
lastStr
)
{
int
startIndex
=
jsonStr
.
indexOf
(
startStr
);
int
lastIndex
=
jsonStr
.
lastIndexOf
(
lastStr
);
return
jsonStr
.
substring
(
startIndex
,
lastIndex
);
}
public
static
void
main
(
String
[]
args
)
throws
IOException
,
URISyntaxException
{
// URL链接
String
targetUrl
=
"https://www.zara.cn/cn/zh/%E5%BA%9C%E7%BB%B8%E9%95%BF%E7%89%88%E8%A1%AC%E8%A1%AB-p08053157.html?v1=31979171&v2=1319321"
;
// 获取网页内容
String
content
=
HttpClientUtil
.
getContentByUrl
(
targetUrl
,
PlatformEnum
.
ZARA
.
getValue
());
// 截取主要的商品数据
int
labelHeadIndex
=
content
.
indexOf
(
"dataLayer"
);
int
labelTailIndex
=
content
.
lastIndexOf
(
";window.zara.viewPayload"
);
String
abv
=
content
.
substring
(
labelHeadIndex
,
labelTailIndex
).
replace
(
"dataLayer = "
,
""
);
System
.
err
.
println
(
abv
);
// 转换为 Json 格式
JSONObject
json
=
JSONObject
.
fromObject
(
abv
);
// System.err.println(json);
// product 对象节点
JSONObject
responseData
=
json
.
getJSONObject
(
"product"
);
// System.err.println(responseData);
// detail 对象节点
JSONObject
details
=
responseData
.
getJSONObject
(
"detail"
);
// System.err.println(details);
// colors 数组节点
JSONArray
colorsArray
=
details
.
getJSONArray
(
"colors"
);
Map
<
Integer
,
JSONObject
>
colorMap
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
colorsArray
.
size
();
i
++)
{
colorMap
.
put
(
i
,
colorsArray
.
getJSONObject
(
i
));
}
System
.
out
.
println
(
colorMap
);
// TODO 取出颜色属性
// sizes 数组节点
Map
<
Integer
,
JSONObject
>
sizesMap
=
new
HashMap
<>();
for
(
Map
.
Entry
<
Integer
,
JSONObject
>
entry
:
colorMap
.
entrySet
()){
// 遍历出每个 colors 对象节点
JSONObject
colors
=
entry
.
getValue
();
JSONArray
sizesArray
=
colors
.
getJSONArray
(
"sizes"
);
for
(
int
i
=
0
;
i
<
sizesArray
.
size
();
i
++)
{
sizesMap
.
put
(
i
,
sizesArray
.
getJSONObject
(
i
));
}
}
System
.
out
.
println
(
sizesMap
);
// TODO 取出价格和尺码属性
// TODO 取出图片属性(图片实体类未知)
}
}
src/main/java/com/diaoyun/zion/chinafrica/enums/PlatformEnum.java
浏览文件 @
50becc76
...
@@ -12,6 +12,9 @@ public enum PlatformEnum implements EnumItemable<PlatformEnum> {
...
@@ -12,6 +12,9 @@ public enum PlatformEnum implements EnumItemable<PlatformEnum> {
TB
(
"淘宝"
,
"tb"
),
TB
(
"淘宝"
,
"tb"
),
TM
(
"天猫"
,
"tm"
),
TM
(
"天猫"
,
"tm"
),
ZARA
(
"西班牙时尚品牌"
,
"zara"
),
UNIQLO
(
"优衣库"
,
"uniqlo"
),
GAP
(
"Gap美国休闲品牌"
,
"gap"
),
UN
(
"未知"
,
"un"
);
UN
(
"未知"
,
"un"
);
private
String
label
;
private
String
label
;
...
...
src/main/java/com/diaoyun/zion/chinafrica/factory/ItemSpiderFactory.java
浏览文件 @
50becc76
...
@@ -4,6 +4,8 @@ import com.diaoyun.zion.chinafrica.bis.IItemSpider;
...
@@ -4,6 +4,8 @@ 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.master.util.SpringContextUtil
;
import
com.diaoyun.zion.master.util.SpringContextUtil
;
import
javax.swing.*
;
/**
/**
* 商品爬虫
* 商品爬虫
*/
*/
...
@@ -12,14 +14,31 @@ public class ItemSpiderFactory {
...
@@ -12,14 +14,31 @@ public class ItemSpiderFactory {
public
static
IItemSpider
getSpider
(
PlatformEnum
platformEnum
)
{
public
static
IItemSpider
getSpider
(
PlatformEnum
platformEnum
)
{
IItemSpider
iItemSpider
;
IItemSpider
iItemSpider
;
switch
(
platformEnum
.
getValue
())
{
switch
(
platformEnum
.
getValue
())
{
// 淘宝
case
"tb"
:{
case
"tb"
:{
iItemSpider
=
(
IItemSpider
)
SpringContextUtil
.
getBean
(
"tbItemSpider"
);
iItemSpider
=
(
IItemSpider
)
SpringContextUtil
.
getBean
(
"tbItemSpider"
);
break
;
break
;
}
}
// 天猫
case
"tm"
:{
case
"tm"
:{
iItemSpider
=
(
IItemSpider
)
SpringContextUtil
.
getBean
(
"tmItemSpider"
);
iItemSpider
=
(
IItemSpider
)
SpringContextUtil
.
getBean
(
"tmItemSpider"
);
break
;
break
;
}
}
// zara 西班牙快时尚品牌
case
"zara"
:{
iItemSpider
=
(
IItemSpider
)
SpringContextUtil
.
getBean
(
"zaraSpider"
);
break
;
}
// 优衣库
case
"uniqlo"
:{
iItemSpider
=
(
IItemSpider
)
SpringContextUtil
.
getBean
(
"uniqloSpider"
);
break
;
}
// Gap 美国休闲品牌
case
"gap"
:{
iItemSpider
=
(
IItemSpider
)
SpringContextUtil
.
getBean
(
"gapSpider"
);
break
;
}
default
:{
default
:{
iItemSpider
=
(
IItemSpider
)
SpringContextUtil
.
getBean
(
"emptyItemSpider"
);
iItemSpider
=
(
IItemSpider
)
SpringContextUtil
.
getBean
(
"emptyItemSpider"
);
break
;
break
;
...
...
src/main/java/com/diaoyun/zion/master/util/JsoupUtil.java
浏览文件 @
50becc76
...
@@ -20,6 +20,7 @@ import java.util.regex.Pattern;
...
@@ -20,6 +20,7 @@ import java.util.regex.Pattern;
public
class
JsoupUtil
{
public
class
JsoupUtil
{
public
static
String
unknow
=
"未知"
;
public
static
String
unknow
=
"未知"
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
JsoupUtil
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
JsoupUtil
.
class
);
/**
/**
* 获取淘宝商品详情的信息 店铺id 名字 主图 sibUrl 等
* 获取淘宝商品详情的信息 店铺id 名字 主图 sibUrl 等
*
*
...
@@ -97,6 +98,7 @@ public class JsoupUtil {
...
@@ -97,6 +98,7 @@ public class JsoupUtil {
}
}
return
configGroup
;
return
configGroup
;
}
}
/**
/**
* 根据script中的变量名获取script中变量相关的内容,特指天猫的返回信息 没什么用,没有商品的规格信息
* 根据script中的变量名获取script中变量相关的内容,特指天猫的返回信息 没什么用,没有商品的规格信息
*
*
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论