From 5a372bb970d611536e757962bed57b12f344f76c Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Wed, 29 Mar 2023 11:22:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=91=E5=9B=BE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 ++ .../xkrs/controller/FirePointController.java | 15 +++ .../java/com/xkrs/model/vo/ReptileVo.java | 34 ++++++ .../java/com/xkrs/utilsnew/ReptileUtils.java | 101 ++++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 src/main/java/com/xkrs/model/vo/ReptileVo.java create mode 100644 src/main/java/com/xkrs/utilsnew/ReptileUtils.java diff --git a/pom.xml b/pom.xml index bf2bb2c..b9a7e15 100644 --- a/pom.xml +++ b/pom.xml @@ -248,6 +248,13 @@ 1.1.1 + + + org.jsoup + jsoup + 1.13.1 + + diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index bbfe315..a33809e 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -4,12 +4,14 @@ import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.service.FirePointService; import com.xkrs.service.StreetService; import com.xkrs.service.impl.FirePointServiceImpl; +import com.xkrs.utilsnew.ReptileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -97,4 +99,17 @@ public class FirePointController { return firePointService.selectFirePointByCode(fireCode); } + /** + * 云图 + */ + @GetMapping("/cloudCharts") + public String cloudCharts() { + try { + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, ReptileUtils.reptileBatch(), locale); + } catch (IOException e) { + e.printStackTrace(); + } + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, null, locale); + } + } diff --git a/src/main/java/com/xkrs/model/vo/ReptileVo.java b/src/main/java/com/xkrs/model/vo/ReptileVo.java new file mode 100644 index 0000000..ab899ed --- /dev/null +++ b/src/main/java/com/xkrs/model/vo/ReptileVo.java @@ -0,0 +1,34 @@ +package com.xkrs.model.vo; + +public class ReptileVo { + + private String imgUrl; + + private String header; + + private String time; + + public String getImgUrl() { + return imgUrl; + } + + public void setImgUrl(String imgUrl) { + this.imgUrl = imgUrl; + } + + public String getHeader() { + return header; + } + + public void setHeader(String header) { + this.header = header; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } +} diff --git a/src/main/java/com/xkrs/utilsnew/ReptileUtils.java b/src/main/java/com/xkrs/utilsnew/ReptileUtils.java new file mode 100644 index 0000000..643c47d --- /dev/null +++ b/src/main/java/com/xkrs/utilsnew/ReptileUtils.java @@ -0,0 +1,101 @@ +package com.xkrs.utilsnew; + +import com.xkrs.model.vo.ReptileVo; +import org.jsoup.Connection; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ReptileUtils { + private static String[] title = { + "https://weather.cma.cn/web/channel-d3236549863e453aab0ccc4027105bad.html", + "https://weather.cma.cn/web/channel-ee6f0049d0bc4846a0396647b5a90cc3.html", + "https://weather.cma.cn/web/channel-24f65d2fb237439d91b6a7fd75a7bfb3.html", + "https://weather.cma.cn/web/channel-37107647b1744dc6b36bb252ca652a63.html" + }; + private static String[] dropBox = {"FY4A真彩色", "FY4A红外", "FY4A可见光", "FY4A水汽"}; + + public static List reptileImages() throws IOException { + List detail = new ArrayList<>(); + for (int i = 0; i < title.length; i++) { + ReptileVo value = new ReptileVo(); + String website = "http://dou.yuanmazg.com"; + Connection.Response response = Jsoup.connect(title[i]).header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36").ignoreContentType(true).timeout(10000).execute(); + + String html = response.body(); + //Jsoup 解析HTML + + Document dom = Jsoup.parse(html); + //选择器 + //获取多个 + Elements select = dom.select("body > div.container > div.row.mt15 > div.col-xs-9 > div.bgwhite > div.pd20 > div.imgblock > img"); + String img_url = select.attr("src");//图片练级 + String time = ""; + Elements select1 = dom.select("#timeList > option:nth-child(1)"); + for (Element ele : select1) { + time = ele.text(); //获取当前标签(元素)的文本值 + } + + String header = dropBox[i]; + value.setHeader(header); + value.setImgUrl(img_url); + value.setTime(time); + detail.add(value); + } + return detail; + } + + public static Map> reptileBatch() throws IOException { + Map> detail = new HashMap<>(4); +// List detail = new ArrayList<>(); + for (int i = 0; i < title.length; i++) { + + Connection.Response response = Jsoup.connect(title[i]).header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36").ignoreContentType(true).timeout(10000).execute(); + + String html = response.body(); + //Jsoup 解析HTML + + Document dom = Jsoup.parse(html); + //选择器 + //获取多个 +// Elements select = dom.select("body > div.container > div.row.mt15 > div.col-xs-9 > div.bgwhite > div.pd20 > div.imgblock > img"); +// String img_url = select.attr("src");//图片练级 + + String img_url = ""; + String header = dropBox[i]; + String time = ""; + List tmp = detail.computeIfAbsent(dropBox[i], v -> new ArrayList<>(40)); + for (int j = 1; j < 21; j++) { + Elements select1 = dom.select("#timeList > option:nth-child(" + j + ")"); + for (Element ele : select1) { + ReptileVo value = new ReptileVo(); + img_url = ele.attr("value"); + time = ele.text(); + value.setHeader(header); + value.setImgUrl(img_url); + value.setTime(time); + tmp.add(value); + } + } + } + return detail; + } + + public static void main(String[] args) { + Map> reptileVos = null; + try { + reptileVos = reptileBatch(); + } catch (IOException e) { + e.printStackTrace(); + } + + System.out.println(reptileVos); + } +}