爬取新闻数据测试

This commit is contained in:
dengli
2023-12-19 20:25:44 +08:00
parent fde0e2f8c7
commit 9526c16469
2 changed files with 9 additions and 36 deletions

View File

@@ -353,12 +353,13 @@ public class StockTask {
public void saveStockNews() {
String news = stockService.getNews();
List<String> newsList = Arrays.asList(news.split("<a href="));
newsList = newsList.subList(1, newsList.size());
newsList.forEach( n -> {
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
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);
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());