爬取新股数据测试

This commit is contained in:
dengli
2023-12-19 14:23:20 +08:00
parent 5e8f90be10
commit 3b634a6134
3 changed files with 45 additions and 0 deletions

View File

@@ -1,7 +1,11 @@
package cn.stock.market.domain.basic.service;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -243,6 +247,36 @@ public class StockService {
return ServerResponse.createBySuccess(marketVO);
}
public ServerResponse getNews() {
String result = "";
try {
// 创建URL对象
URL url = new URL("https://www.business-standard.com/markets/news");
// 打开URL连接
URLConnection connection = url.openConnection();
// 获取输入流
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
// 读取数据
StringBuilder data = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
data.append(line);
}
// 关闭输入流
reader.close();
// 输出抓取到的数据
result = data.toString();
} catch (IOException e) {
e.printStackTrace();
}
return ServerResponse.createBySuccessMsg(result);
}
public ServerResponse getStock(int pageNum, int pageSize, String keyWords, String stockPlate, String stockType,
HttpServletRequest request) {
Page<Stock> page = repository.findStockListByKeyWords(keyWords, stockPlate, stockType, 0, PageParam.of(pageNum, pageSize));

View File

@@ -1,6 +1,10 @@
package cn.stock.market.infrastructure.api.investing;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

View File

@@ -146,6 +146,13 @@ public class StockApiController {
return ServerResponse.createBySuccess(InvestingInvokerApis.of().__page_nifty100(pageNum, pageSize));
}
@RequestMapping({"getINDNews.do"})
@ApiOperation(value = "印度热门股票列表", httpMethod = "GET")
@ResponseBody
public ServerResponse getINDNews() {
return ServerResponse.createBySuccess(stockService.getNews());
}
//印度股票时线-K线
@RequestMapping({"getINDTimeK.do"})
@ApiOperation(value = "印度股票K线", httpMethod = "GET")