Commit 5d538d04 by chenweitao

Merge branch 'working' into 'master'

更新淘宝热搜爬取程序

See merge request !116
parents 0c4edfc8 311021ff
...@@ -520,17 +520,17 @@ public class GatherTimer { ...@@ -520,17 +520,17 @@ public class GatherTimer {
TipsUtils.addHotList(HotSearchType.快手热榜.name(), kuaiShouList); TipsUtils.addHotList(HotSearchType.快手热榜.name(), kuaiShouList);
logger.info("快手热榜采集结束..."); logger.info("快手热榜采集结束...");
} }
// /** /**
// *淘宝热搜采集 *淘宝热搜采集
// */ */
// @Async(value = "myScheduler") @Async(value = "myScheduler")
// @Scheduled(cron = "0 * * * * ? ") @Scheduled(cron = "0 * * * * ? ")
// public void crawlerTaoBao(){ public void crawlerTaoBao(){
// logger.info("淘宝热搜开始采集..."); logger.info("淘宝热搜开始采集...");
// Date date = DateUtils.getMillSecondTime(new Date()); Date date = DateUtils.getMillSecondTime(new Date());
// List<HotSearchList> taoBaoList = TaoBaoHotSearchCrawler.taoBaoHotSearch(date); List<HotSearchList> taoBaoList = TaoBaoHotSearchCrawler.taoBaoHotSearch(date);
// logger.info("{}, 淘宝热搜此轮采集到的数据量为:{}", new Date(), taoBaoList != null ? taoBaoList.size() : 0); logger.info("{}, 淘宝热搜此轮采集到的数据量为:{}", new Date(), taoBaoList != null ? taoBaoList.size() : 0);
// TipsUtils.addHotList(HotSearchType.淘宝热搜.name(), taoBaoList); TipsUtils.addHotList(HotSearchType.淘宝热搜.name(), taoBaoList);
// logger.info("淘宝热搜采集结束..."); logger.info("淘宝热搜采集结束...");
// } }
} }
...@@ -7,6 +7,7 @@ import javax.script.Invocable; ...@@ -7,6 +7,7 @@ import javax.script.Invocable;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import java.io.*; import java.io.*;
import java.util.stream.Collectors;
@Log4j2 @Log4j2
public class TaoBaoUtils { public class TaoBaoUtils {
...@@ -18,17 +19,18 @@ public class TaoBaoUtils { ...@@ -18,17 +19,18 @@ public class TaoBaoUtils {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
try { try {
//如果js存在文件里 //如果js存在文件里
Resource aesJs = new ClassPathResource("taobao.js"); Resource aesJs = new ClassPathResource("/taobao.js",TaoBaoUtils.class.getClassLoader());
log.info("获取aesJs: {}",aesJs);
InputStream inputStream = aesJs.getInputStream(); InputStream inputStream = aesJs.getInputStream();
engine.eval(new BufferedReader(new InputStreamReader(inputStream))); // engine.eval(new BufferedReader(new InputStreamReader(inputStream)));
engine.eval(new BufferedReader(new InputStreamReader(inputStream))
.lines().parallel().collect(Collectors.joining(System.lineSeparator())));
//3.将引擎转换为Invocable,这样才可以掉用js的方法 //3.将引擎转换为Invocable,这样才可以掉用js的方法
Invocable invocable = (Invocable) engine; Invocable invocable = (Invocable) engine;
//4.使用 invocable.invokeFunction掉用js脚本里的方法,第一個参数为方法名,后面的参数为被调用的js方法的入参 //4.使用 invocable.invokeFunction掉用js脚本里的方法,第一個参数为方法名,后面的参数为被调用的js方法的入参
scriptResult = (String) invocable.invokeFunction("h", sign); scriptResult = (String) invocable.invokeFunction("h", sign);
} catch (Exception e) { } catch (Exception e) {
log.error("Error executing script: ", e.getMessage()); log.error("Error executing script: ", e);
} }
return scriptResult; return scriptResult;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment