Feat: 从指定 url 获取 HTML 文件

This commit is contained in:
2025-10-16 21:27:47 +08:00
parent a064e422eb
commit 644af33c20
4 changed files with 52 additions and 11 deletions
@@ -1,18 +1,9 @@
package cn.hezhaohui.fund;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.boot.SpringApplication;
public class Application {
public static void main(String[] args) {
String htmlString = "<html><head><title>My title</title></head>"
+ "<body>Body content</body></html>";
Document doc = Jsoup.parse(htmlString);
String title = doc.title();
String body = doc.body().text();
System.out.printf("Title: %s%n", title);
System.out.printf("Body: %s", body);
SpringApplication.run(Application.class, args);
}
}
@@ -0,0 +1,12 @@
package cn.hezhaohui.fund.util;
import cn.hutool.http.HttpUtil;
import org.springframework.stereotype.Component;
@Component
public class WebUtil {
public static String getContentByUrl(String url) {
String string = HttpUtil.get(url);
return string;
}
}
@@ -0,0 +1,15 @@
package cn.hezhaohui.fund.util;
import cn.hutool.core.lang.Assert;
import org.junit.jupiter.api.Test;
public class WebUtilTest {
@Test
void getContentByUrl() {
String content = WebUtil.getContentByUrl("https://fund.eastmoney.com/001068.html");
System.out.println(content);
Assert.notNull(content);
}
}