Commit 311021ff by leiliangliang

更新淘宝热搜爬取程序

parent b0801e82
......@@ -520,17 +520,17 @@ public class GatherTimer {
TipsUtils.addHotList(HotSearchType.快手热榜.name(), kuaiShouList);
logger.info("快手热榜采集结束...");
}
// /**
// *淘宝热搜采集
// */
// @Async(value = "myScheduler")
// @Scheduled(cron = "0 * * * * ? ")
// public void crawlerTaoBao(){
// logger.info("淘宝热搜开始采集...");
// Date date = DateUtils.getMillSecondTime(new Date());
// List<HotSearchList> taoBaoList = TaoBaoHotSearchCrawler.taoBaoHotSearch(date);
// logger.info("{}, 淘宝热搜此轮采集到的数据量为:{}", new Date(), taoBaoList != null ? taoBaoList.size() : 0);
// TipsUtils.addHotList(HotSearchType.淘宝热搜.name(), taoBaoList);
// logger.info("淘宝热搜采集结束...");
// }
/**
*淘宝热搜采集
*/
@Async(value = "myScheduler")
@Scheduled(cron = "0 * * * * ? ")
public void crawlerTaoBao(){
logger.info("淘宝热搜开始采集...");
Date date = DateUtils.getMillSecondTime(new Date());
List<HotSearchList> taoBaoList = TaoBaoHotSearchCrawler.taoBaoHotSearch(date);
logger.info("{}, 淘宝热搜此轮采集到的数据量为:{}", new Date(), taoBaoList != null ? taoBaoList.size() : 0);
TipsUtils.addHotList(HotSearchType.淘宝热搜.name(), taoBaoList);
logger.info("淘宝热搜采集结束...");
}
}
......@@ -7,6 +7,7 @@ import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.*;
import java.util.stream.Collectors;
@Log4j2
public class TaoBaoUtils {
......@@ -18,17 +19,18 @@ public class TaoBaoUtils {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
try {
//如果js存在文件里
Resource aesJs = new ClassPathResource("taobao.js");
Resource aesJs = new ClassPathResource("/taobao.js",TaoBaoUtils.class.getClassLoader());
log.info("获取aesJs: {}",aesJs);
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的方法
Invocable invocable = (Invocable) engine;
//4.使用 invocable.invokeFunction掉用js脚本里的方法,第一個参数为方法名,后面的参数为被调用的js方法的入参
scriptResult = (String) invocable.invokeFunction("h", sign);
} catch (Exception e) {
log.error("Error executing script: ", e.getMessage());
log.error("Error executing script: ", e);
}
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