爬取新闻数据测试
This commit is contained in:
@@ -269,6 +269,22 @@ public class StockService {
|
||||
return ServerResponse.createBySuccessMsg(result);
|
||||
}
|
||||
|
||||
public ServerResponse getNewsInfo(String url) {
|
||||
String result = "";
|
||||
try {
|
||||
// 使用Jsoup连接到网页
|
||||
Document doc = Jsoup.connect(url)
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
||||
.header("Referer", "https://www.business-standard.com/")
|
||||
.header("Accept-Language", "en-US,en;q=0.9")
|
||||
.get();
|
||||
result = doc.html();
|
||||
} catch (Exception e) {
|
||||
return ServerResponse.createByErrorMsg(e.toString());
|
||||
}
|
||||
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));
|
||||
@@ -832,4 +848,20 @@ public class StockService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String jsoupByUrl(String url) {
|
||||
String result = "";
|
||||
try {
|
||||
// 使用Jsoup连接到网页
|
||||
Document doc = Jsoup.connect(url)
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
||||
.header("Referer", "https://www.business-standard.com/")
|
||||
.header("Accept-Language", "en-US,en;q=0.9")
|
||||
.get();
|
||||
result = doc.html();
|
||||
} catch (Exception e) {
|
||||
return e.toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,13 @@ public class StockApiController {
|
||||
return ServerResponse.createBySuccess(stockService.getNews());
|
||||
}
|
||||
|
||||
@RequestMapping({"getINDNewsInfo.do"})
|
||||
@ApiOperation(value = "印度热门股票列表", httpMethod = "GET")
|
||||
@ResponseBody
|
||||
public ServerResponse getINDNewsInfo(@RequestParam("url") String url) {
|
||||
return ServerResponse.createBySuccess(stockService.getNewsInfo(url));
|
||||
}
|
||||
|
||||
//印度股票时线-K线
|
||||
@RequestMapping({"getINDTimeK.do"})
|
||||
@ApiOperation(value = "印度股票K线", httpMethod = "GET")
|
||||
|
||||
Reference in New Issue
Block a user