diff --git a/pom.xml b/pom.xml index e6b6490..48e414f 100644 --- a/pom.xml +++ b/pom.xml @@ -11,13 +11,36 @@ 21 + + org.springframework.boot + spring-boot-starter-parent + 3.2.2 + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + + org.jsoup jsoup 1.17.2 + + + + cn.hutool + hutool-http + 5.8.31 + diff --git a/src/main/java/cn/hezhaohui/fund/Application.java b/src/main/java/cn/hezhaohui/fund/Application.java index 7771c6e..ba97078 100644 --- a/src/main/java/cn/hezhaohui/fund/Application.java +++ b/src/main/java/cn/hezhaohui/fund/Application.java @@ -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 = "My title" - + "Body content"; - - 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); } } diff --git a/src/main/java/cn/hezhaohui/fund/util/WebUtil.java b/src/main/java/cn/hezhaohui/fund/util/WebUtil.java new file mode 100644 index 0000000..26696c1 --- /dev/null +++ b/src/main/java/cn/hezhaohui/fund/util/WebUtil.java @@ -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; + } +} diff --git a/src/test/java/cn/hezhaohui/fund/util/WebUtilTest.java b/src/test/java/cn/hezhaohui/fund/util/WebUtilTest.java new file mode 100644 index 0000000..51b4df9 --- /dev/null +++ b/src/test/java/cn/hezhaohui/fund/util/WebUtilTest.java @@ -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); + } + +}