Merge branch 'dengli2024/1/11' into 'main'
新闻定时任务 See merge request india/india_market_java!5
This commit is contained in:
@@ -272,8 +272,9 @@ public class StockService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getNewsInfo(String url) {
|
||||
public List<String> getNewsInfo(String url) {
|
||||
String result = "";
|
||||
List<String> list = new ArrayList<>();
|
||||
try {
|
||||
// 使用Jsoup连接到网页
|
||||
Document doc = Jsoup.connect(url)
|
||||
@@ -281,11 +282,14 @@ public class StockService {
|
||||
.header("Referer", "https://www.business-standard.com/")
|
||||
.header("Accept-Language", "en-US,en;q=0.9")
|
||||
.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) {
|
||||
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,
|
||||
|
||||
@@ -117,15 +117,15 @@ public class InvestingTask {
|
||||
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
||||
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 title = n.substring(n.indexOf("html\">") + 6, n.indexOf("<div class=\"short-video-img\">") - 47);
|
||||
|
||||
SiteNews siteNews = new SiteNews();
|
||||
siteNews.setAddTime(new Date());
|
||||
siteNews.setSourceId(id);
|
||||
siteNews.setTitle(title);
|
||||
siteNews.setDescription(time);
|
||||
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));
|
||||
if (list.size() == 0) {
|
||||
newsRepository.save(siteNews);
|
||||
|
||||
Reference in New Issue
Block a user