新闻测试

This commit is contained in:
dengli
2024-01-10 10:34:21 +08:00
parent c646988219
commit a9fe1c39a7

View File

@@ -272,8 +272,9 @@ public class StockService {
return result; return result;
} }
public String getNewsInfo(String url) { public List<String> getNewsInfo(String url) {
String result = ""; String result = "";
List<String> list = new ArrayList<>();
try { try {
// 使用Jsoup连接到网页 // 使用Jsoup连接到网页
Document doc = Jsoup.connect(url) Document doc = Jsoup.connect(url)
@@ -281,12 +282,14 @@ 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") + 13, doc.html().indexOf(",\"author\":") - 1); result = doc.html().substring(doc.html().indexOf("articleBody") + 13, doc.html().indexOf(",\"author\":") - 1);
result = doc.html(); list.add(result);
list.add(doc.html().substring(doc.html().indexOf("twitter:description") + 32, doc.html().indexOf("<meta property=\"article:published_time") - 7));
} catch (Exception e) { } catch (Exception e) {
return e.toString(); list.add(e.toString());
return list;
} }
return result; return list;
} }
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,