爬取新闻数据测试
This commit is contained in:
@@ -153,28 +153,28 @@ public class StockApiController {
|
||||
@ResponseBody
|
||||
public ServerResponse getINDNews() {
|
||||
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);
|
||||
|
||||
return ServerResponse.createBySuccessMsg(news);
|
||||
//List<String> newsList = Arrays.asList(news.split("<a href="));
|
||||
//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);
|
||||
//
|
||||
// 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<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
|
||||
// if (list.size() == 0) {
|
||||
// newsRepository.save(siteNews);
|
||||
// }
|
||||
//});
|
||||
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<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
|
||||
if (list.size() == 0) {
|
||||
newsRepository.save(siteNews);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequestMapping({"getINDNewsInfo.do"})
|
||||
|
||||
Reference in New Issue
Block a user