新闻定时任务

This commit is contained in:
dengli
2024-01-11 18:04:32 +08:00
parent e98b6d0463
commit ef392a7fe7
2 changed files with 11 additions and 7 deletions

View File

@@ -272,8 +272,9 @@ public class StockService {
return result; return result;
} }
public String getNewsInfo(String url) { public List<String> getNewsInfo(String url) {
String result = ""; String result = "";
List<String> list = new ArrayList<>();
try { try {
// 使用Jsoup连接到网页 // 使用Jsoup连接到网页
Document doc = Jsoup.connect(url) Document doc = Jsoup.connect(url)
@@ -281,11 +282,14 @@ public class StockService {
.header("Referer", "https://www.business-standard.com/") .header("Referer", "https://www.business-standard.com/")
.header("Accept-Language", "en-US,en;q=0.9") .header("Accept-Language", "en-US,en;q=0.9")
.get(); .get();
result = doc.html().substring(doc.html().indexOf("articleBody") + 15, doc.html().indexOf(",\"author\":") - 1); result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1);
list.add(result);
list.add(doc.html().substring(doc.html().indexOf("og:title") + 19, doc.html().indexOf("<meta property=\"og:url") - 5));
} catch (Exception e) { } catch (Exception e) {
return e.toString(); list.add(e.toString());
return list;
} }
return result; return list;
} }
public ServerResponse getStock(int pageNum, int pageSize, String keyWords, String stockPlate, String stockType, public ServerResponse getStock(int pageNum, int pageSize, String keyWords, String stockPlate, String stockType,

View File

@@ -117,15 +117,15 @@ public class InvestingTask {
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_")); String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
String imgUrl = n.substring(n.indexOf("img src=") + 9, n.indexOf("?")); String imgUrl = n.substring(n.indexOf("img src=") + 9, n.indexOf("?"));
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9); String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
String title = n.substring(n.indexOf("html\">") + 6, n.indexOf("<div class=\"short-video-img\">") - 47);
SiteNews siteNews = new SiteNews(); SiteNews siteNews = new SiteNews();
siteNews.setAddTime(new Date()); siteNews.setAddTime(new Date());
siteNews.setSourceId(id); siteNews.setSourceId(id);
siteNews.setTitle(title);
siteNews.setDescription(time); siteNews.setDescription(time);
siteNews.setImgurl(imgUrl); siteNews.setImgurl(imgUrl);
siteNews.setContent(stockService.getNewsInfo(contentUrl)); List<String> newsInfo = stockService.getNewsInfo(contentUrl);
siteNews.setContent(newsInfo.get(0));
siteNews.setTitle(newsInfo.get(1));
List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id)); List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
if (list.size() == 0) { if (list.size() == 0) {
newsRepository.save(siteNews); newsRepository.save(siteNews);