|
|
@@ -3,6 +3,7 @@ package com.unis.news.tasksNews;
|
|
3
|
3
|
import com.unis.config.NewsUrl;
|
|
4
|
4
|
import com.unis.news.entity.BizSinQinghaiNews;
|
|
5
|
5
|
import com.unis.news.service.BizSinQinghaiNewsService;
|
|
|
6
|
+import com.unis.news.service.BizSinStateCouncilNoticeService;
|
|
6
|
7
|
import lombok.extern.slf4j.Slf4j;
|
|
7
|
8
|
import org.htmlunit.BrowserVersion;
|
|
8
|
9
|
import org.htmlunit.Page;
|
|
|
@@ -26,67 +27,30 @@ public class TasksNewsRunning {
|
|
26
|
27
|
@Resource
|
|
27
|
28
|
private BizSinQinghaiNewsService newsService;
|
|
28
|
29
|
@Resource
|
|
|
30
|
+ private BizSinStateCouncilNoticeService bizSinStateCouncilNoticeService;
|
|
|
31
|
+ @Resource
|
|
29
|
32
|
private NewsUrl newsUrl;
|
|
30
|
33
|
@Resource
|
|
31
|
34
|
private WebClient webClient;
|
|
32
|
35
|
|
|
33
|
|
- /**
|
|
34
|
|
- * test
|
|
35
|
|
- */
|
|
36
|
|
- // n秒 直接在方法上使用注解即可完成扫描
|
|
37
|
|
- @Scheduled(cron = "*/20 * * * * ?")
|
|
38
|
|
- public void run() throws Exception {
|
|
39
|
|
- // 测试查询
|
|
40
|
|
- List<BizSinQinghaiNews> list = newsService.list();
|
|
41
|
|
- log.info("test get all list for news: {}", list);
|
|
42
|
|
-
|
|
43
|
|
- log.info("newsUrl stateCouncil: {}", newsUrl.getStateCouncil());
|
|
44
|
|
- log.info("newsUrl qinghai: {}", newsUrl.getQinghai());
|
|
45
|
36
|
|
|
46
|
|
- final HtmlPage page = webClient.getPage(newsUrl.getQinghai());
|
|
47
|
|
- log.info("page: {}", page);
|
|
48
|
|
-
|
|
49
|
|
- List<HtmlAnchor> divList = page.getByXPath("//a");
|
|
50
|
|
- /*for (HtmlAnchor node : divList) {
|
|
51
|
|
- log.info("webClient stateCouncil asXml: {}", node.asXml());
|
|
52
|
|
- log.info("webClient stateCouncil href: {}", node.getAttribute("href"));
|
|
53
|
|
- log.info("webClient stateCouncil href: {}", node.getAttribute("href"));
|
|
54
|
|
- log.info("webClient stateCouncil src: {}", node.getAttribute("src"));
|
|
55
|
|
- log.info("webClient stateCouncil getLocalName: {}", node.getLocalName());
|
|
56
|
|
- }*/
|
|
57
|
|
-
|
|
58
|
|
- log.info("----每天n秒执行---");
|
|
59
|
|
- }
|
|
60
|
37
|
/**
|
|
61
|
38
|
* 抓取青海省政务网站数据,晚上3点执行一次
|
|
62
|
39
|
*/
|
|
63
|
40
|
@Scheduled(cron = "0 0 3 * * ?")
|
|
64
|
|
- public void qinghaiNewsrun() throws Exception {
|
|
|
41
|
+ public void qinghaiNewsun() {
|
|
65
|
42
|
newsService.taskAction();
|
|
66
|
|
- log.info("----每天n秒执行---");
|
|
|
43
|
+ log.info("----抓取青海省政务网站数据,晚上3点执行一次---");
|
|
|
44
|
+ }
|
|
|
45
|
+ /**
|
|
|
46
|
+ * 抓取国务院网站数据,晚上3点执行一次
|
|
|
47
|
+ */
|
|
|
48
|
+ @Scheduled(cron = "0 0 3 * * ?")
|
|
|
49
|
+ public void stateCouncilNoticeun() {
|
|
|
50
|
+ bizSinStateCouncilNoticeService.taskAction();
|
|
|
51
|
+ log.info("----抓取国务院网站数据,晚上3点执行一次---");
|
|
67
|
52
|
}
|
|
68
|
53
|
|
|
69
|
|
- public static void main(String[] args) {
|
|
70
|
|
- WebClient webClient=null;
|
|
71
|
|
- try {
|
|
72
|
|
- webClient= new WebClient(BrowserVersion.CHROME); //定义一个WebClient
|
|
73
|
|
- final HtmlPage page=webClient.getPage("http://fgw.qinghai.gov.cn//"); //从指定URL获取HtmlPage
|
|
74
|
|
-
|
|
75
|
|
- List<HtmlAnchor> divList=page.getByXPath("//a");
|
|
76
|
|
- for (HtmlAnchor node : divList) {
|
|
77
|
|
- System.out.println("***********************************************8");
|
|
78
|
|
- System.out.println("输出:"+node.asXml());
|
|
79
|
|
- System.out.println("输出1:"+node.getAttribute("href"));
|
|
80
|
|
- System.out.println("输出2:"+node.getAttribute("src"));
|
|
81
|
|
- System.out.println("输出3:"+node.getLocalName());
|
|
82
|
|
- }
|
|
83
|
54
|
|
|
84
|
|
- } catch (Exception e) {
|
|
85
|
|
- // TODO: handle exception
|
|
86
|
|
- e.printStackTrace();
|
|
87
|
|
- }finally {
|
|
88
|
|
- webClient.close(); //关闭客户端
|
|
89
|
|
- }
|
|
90
|
|
- }
|
|
91
|
55
|
|
|
92
|
56
|
}
|