爬取新闻数据测试

This commit is contained in:
dengli
2023-12-19 16:44:38 +08:00
parent 92cb4823a3
commit 2ef3844fbb
2 changed files with 17 additions and 7 deletions

View File

@@ -269,7 +269,7 @@ public class StockService {
return ServerResponse.createBySuccessMsg(result); return ServerResponse.createBySuccessMsg(result);
} }
public ServerResponse getNewsInfo(String url) { public String getNewsInfo(String url) {
String result = ""; String result = "";
try { try {
// 使用Jsoup连接到网页 // 使用Jsoup连接到网页
@@ -278,11 +278,11 @@ public class StockService {
.header("Referer", "https://www.business-standard.com/") .header("Referer", "https://www.business-standard.com/")
.header("Accept-Language", "en-US,en;q=0.9") .header("Accept-Language", "en-US,en;q=0.9")
.get(); .get();
result = doc.html().substring(doc.html().indexOf(",\"articleBody\":\"" + 16), doc.html().indexOf(",\"author\"")); result = doc.html().substring(doc.html().indexOf("articleBody") + 15,doc.html().indexOf("author") - 5);
} catch (Exception e) { } catch (Exception e) {
return ServerResponse.createByErrorMsg(e.toString()); return e.toString();
} }
return ServerResponse.createBySuccessMsg(result); return result;
} }
public ServerResponse getStock(int pageNum, int pageSize, String keyWords, String stockPlate, String stockType, public ServerResponse getStock(int pageNum, int pageSize, String keyWords, String stockPlate, String stockType,

File diff suppressed because one or more lines are too long