Merge remote-tracking branch 'origin/branch_straw_fire_point' into branch_straw_fire_point_two

This commit is contained in:
liuchengqian 2023-03-29 11:40:42 +08:00
commit 8a14852894
4 changed files with 157 additions and 0 deletions

View File

@ -248,6 +248,13 @@
<version>1.1.1</version> <version>1.1.1</version>
</dependency> </dependency>
<!--爬虫依赖-->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -4,12 +4,14 @@ import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.service.FirePointService; import com.xkrs.service.FirePointService;
import com.xkrs.service.StreetService; import com.xkrs.service.StreetService;
import com.xkrs.service.impl.FirePointServiceImpl; import com.xkrs.service.impl.FirePointServiceImpl;
import com.xkrs.utilsnew.ReptileUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -97,4 +99,17 @@ public class FirePointController {
return firePointService.selectFirePointByCode(fireCode); 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);
}
} }

View File

@ -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;
}
}

View File

@ -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<ReptileVo> reptileImages() throws IOException {
List<ReptileVo> 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<String, List<ReptileVo>> reptileBatch() throws IOException {
Map<String, List<ReptileVo>> detail = new HashMap<>(4);
// List<ReptileVo> 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<ReptileVo> 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<String, List<ReptileVo>> reptileVos = null;
try {
reptileVos = reptileBatch();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(reptileVos);
}
}