Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
15f5304f
提交
15f5304f
authored
9月 16, 2019
作者:
zhengfg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
加入future过期检测
上级
299d967d
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
22 行增加
和
13 行删除
+22
-13
IItemSpider.java
...ain/java/com/diaoyun/zion/chinafrica/bis/IItemSpider.java
+2
-1
TbItemSpider.java
...va/com/diaoyun/zion/chinafrica/bis/impl/TbItemSpider.java
+2
-1
TmItemSpider.java
...va/com/diaoyun/zion/chinafrica/bis/impl/TmItemSpider.java
+2
-1
SpiderController.java
.../diaoyun/zion/chinafrica/controller/SpiderController.java
+2
-1
SpiderService.java
...va/com/diaoyun/zion/chinafrica/service/SpiderService.java
+2
-1
SpiderServiceImpl.java
...aoyun/zion/chinafrica/service/impl/SpiderServiceImpl.java
+2
-1
TranslateHelper.java
...in/java/com/diaoyun/zion/master/util/TranslateHelper.java
+5
-3
WordposHelper.java
...main/java/com/diaoyun/zion/master/util/WordposHelper.java
+4
-3
ZionApplicationTests.java
src/test/java/com/diaoyun/zion/ZionApplicationTests.java
+1
-1
没有找到文件。
src/main/java/com/diaoyun/zion/chinafrica/bis/IItemSpider.java
浏览文件 @
15f5304f
...
...
@@ -6,6 +6,7 @@ import java.io.IOException;
import
java.net.URISyntaxException
;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
/**
* 商品爬虫接口
...
...
@@ -17,6 +18,6 @@ public interface IItemSpider {
* @param targetUrl
* @return
*/
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
;
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
,
TimeoutException
;
}
src/main/java/com/diaoyun/zion/chinafrica/bis/impl/TbItemSpider.java
浏览文件 @
15f5304f
...
...
@@ -34,6 +34,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeoutException
;
/**
* 淘宝网数据爬虫
...
...
@@ -46,7 +47,7 @@ public class TbItemSpider implements IItemSpider {
private
static
final
String
taobaoUrl
=
"https://item.taobao.com/item.htm?"
;
@Override
public
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
{
public
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
//主要是判断淘宝的url是手机端还是PC端,如果是手机端,那么还需要提取相关参数,组成新的url;还有去除链接中一些会引起请求错误的参数
targetUrl
=
processUrl
(
targetUrl
);
List
<
Map
<
String
,
Object
>>
futureList
=
new
ArrayList
<>();
...
...
src/main/java/com/diaoyun/zion/chinafrica/bis/impl/TmItemSpider.java
浏览文件 @
15f5304f
...
...
@@ -19,6 +19,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
/**
* 天猫数据爬虫
...
...
@@ -31,7 +32,7 @@ public class TmItemSpider implements IItemSpider {
private
static
final
String
tmallUrl
=
"https://detail.m.tmall.com/item.htm?"
;
@Override
public
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
{
public
JSONObject
captureItem
(
String
targetUrl
)
throws
URISyntaxException
,
IOException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
//主要获取id参数,组成新链接
//targetUrl=processUrl(targetUrl);
List
<
Map
<
String
,
Object
>>
futureList
=
new
ArrayList
<>();
...
...
src/main/java/com/diaoyun/zion/chinafrica/controller/SpiderController.java
浏览文件 @
15f5304f
...
...
@@ -16,6 +16,7 @@ import java.net.URISyntaxException;
import
java.net.URLDecoder
;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
/**
* 爬取网络相关数据Controller
...
...
@@ -34,7 +35,7 @@ public class SpiderController {
@ApiOperation
(
"获取商品详情"
)
@PostMapping
(
"/item/detail"
)
@ResponseBody
public
Result
getItemDetail
(
@ApiParam
(
"targetUrl 需要先进行url编码"
)
@RequestBody
DetailParamVo
detailParamVo
)
throws
InterruptedException
,
ExecutionException
,
URISyntaxException
,
IOException
{
public
Result
getItemDetail
(
@ApiParam
(
"targetUrl 需要先进行url编码"
)
@RequestBody
DetailParamVo
detailParamVo
)
throws
InterruptedException
,
ExecutionException
,
URISyntaxException
,
IOException
,
TimeoutException
{
String
targetUrl
=
URLDecoder
.
decode
(
detailParamVo
.
getTargetUrl
(),
"UTF-8"
);
JSONObject
itemMap
=
spiderService
.
getItemDetail
(
targetUrl
);
Result
result
=
new
Result
(
itemMap
,
"商品规格信息"
);
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/SpiderService.java
浏览文件 @
15f5304f
...
...
@@ -7,6 +7,7 @@ import java.math.BigDecimal;
import
java.net.URISyntaxException
;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
public
interface
SpiderService
{
/**
...
...
@@ -14,7 +15,7 @@ public interface SpiderService {
* @param targetUrl
* @return
*/
JSONObject
getItemDetail
(
String
targetUrl
)
throws
InterruptedException
,
IOException
,
ExecutionException
,
URISyntaxException
;
JSONObject
getItemDetail
(
String
targetUrl
)
throws
InterruptedException
,
IOException
,
ExecutionException
,
URISyntaxException
,
TimeoutException
;
/**
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/impl/SpiderServiceImpl.java
浏览文件 @
15f5304f
...
...
@@ -17,12 +17,13 @@ import java.net.URISyntaxException;
import
java.nio.charset.Charset
;
import
java.util.*
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
@Service
(
"spiderService"
)
public
class
SpiderServiceImpl
implements
SpiderService
{
@Override
public
JSONObject
getItemDetail
(
String
targetUrl
)
throws
InterruptedException
,
IOException
,
ExecutionException
,
URISyntaxException
{
public
JSONObject
getItemDetail
(
String
targetUrl
)
throws
InterruptedException
,
IOException
,
ExecutionException
,
URISyntaxException
,
TimeoutException
{
//判断链接属于哪个平台
PlatformEnum
platformEnum
=
judgeUrlType
(
targetUrl
);
...
...
src/main/java/com/diaoyun/zion/master/util/TranslateHelper.java
浏览文件 @
15f5304f
...
...
@@ -11,6 +11,8 @@ import java.util.List;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
/**
* 腾讯翻译
...
...
@@ -44,20 +46,20 @@ public class TranslateHelper {
* 等待翻译结果
* @param futureList
*/
public
static
void
waitForResult
(
List
<
Map
<
String
,
Object
>>
futureList
)
throws
ExecutionException
,
InterruptedException
{
public
static
void
waitForResult
(
List
<
Map
<
String
,
Object
>>
futureList
)
throws
ExecutionException
,
InterruptedException
,
TimeoutException
{
for
(
Map
<
String
,
Object
>
futureMap:
futureList
)
{
Future
<
Map
<
String
,
Object
>>
future
=
(
Future
<
Map
<
String
,
Object
>>)
futureMap
.
get
(
"future"
);
Map
<
String
,
Object
>
valeMap
=
(
Map
<
String
,
Object
>
)
futureMap
.
get
(
"value"
);
while
(!
future
.
isDone
());
//Future返回如果没有完成,则一直循环等待,直到Future返回完成
Map
<
String
,
Object
>
resultMap
=
future
.
get
();
Map
<
String
,
Object
>
resultMap
=
future
.
get
(
10000
,
TimeUnit
.
MILLISECONDS
);
String
targetText
=
"unknow"
;
if
(
resultMap
!=
null
&&(
int
)
resultMap
.
get
(
"ret"
)==
0
)
{
Map
<
String
,
Object
>
dataMap
=(
Map
<
String
,
Object
>)
resultMap
.
get
(
"data"
);
targetText
=
(
String
)
dataMap
.
get
(
"target_text"
);
valeMap
.
put
(
"translate"
,
targetText
);
}
else
{
logger
.
error
(
"翻译出错"
);
}
valeMap
.
put
(
"translate"
,
targetText
);
}
}
}
src/main/java/com/diaoyun/zion/master/util/WordposHelper.java
浏览文件 @
15f5304f
...
...
@@ -14,6 +14,8 @@ import java.util.List;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
/**
* 分词
...
...
@@ -48,13 +50,12 @@ public class WordposHelper {
* 等待翻译结果
* @param futureList
*/
public
static
void
waitForResult
(
List
<
Map
<
String
,
Object
>>
futureList
)
throws
ExecutionException
,
InterruptedException
{
public
static
void
waitForResult
(
List
<
Map
<
String
,
Object
>>
futureList
)
throws
ExecutionException
,
InterruptedException
,
TimeoutException
{
for
(
Map
<
String
,
Object
>
futureMap:
futureList
)
{
Future
<
Map
<
String
,
Object
>>
future
=
(
Future
<
Map
<
String
,
Object
>>)
futureMap
.
get
(
"future"
);
Map
<
String
,
Object
>
valeMap
=
(
Map
<
String
,
Object
>
)
futureMap
.
get
(
"value"
);
while
(!
future
.
isDone
());
//Future返回如果没有完成,则一直循环等待,直到Future返回完成
Map
<
String
,
Object
>
resultMap
=
future
.
get
();
//logger.info(resultMap.toString());
Map
<
String
,
Object
>
resultMap
=
future
.
get
(
10000
,
TimeUnit
.
MILLISECONDS
);
if
(
resultMap
!=
null
&&(
int
)
resultMap
.
get
(
"ret"
)==
0
)
{
Map
<
String
,
Object
>
dataMap
=(
Map
<
String
,
Object
>)
resultMap
.
get
(
"data"
);
JSONArray
tokens
=
(
JSONArray
)
dataMap
.
get
(
"base_tokens"
);
...
...
src/test/java/com/diaoyun/zion/ZionApplicationTests.java
浏览文件 @
15f5304f
...
...
@@ -42,7 +42,7 @@ public class ZionApplicationTests {
//private List<Map<String, Object>> futureList = new ArrayList<Map<String, Object>>();
@Test
public
void
contextLoads
()
throws
InterruptedException
,
URISyntaxException
,
IOException
,
ExecutionException
,
StripeException
{
public
void
contextLoads
()
throws
InterruptedException
,
URISyntaxException
,
IOException
,
ExecutionException
,
StripeException
,
TimeoutException
{
/*Template t = config.getTemplate("email-template.ftl");
Map<String,String> model=new HashMap<>();
model.put("Name","yonghuming");
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论