File tree Expand file tree Collapse file tree
src/main/java/com/fengwenyi/javalib/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515:star : Features
1616
1717- 【http】新增 http 模块,提供Http调用工具类 HttpUtils。
18+ - 【util】新增 JsoupUtils,从 html 中解析标题。
1819
1920
2021
Original file line number Diff line number Diff line change 3333 <transmittable-thread-local .version>2.14.2</transmittable-thread-local .version>
3434 <maven-javadoc-plugin .version>3.4.1</maven-javadoc-plugin .version>
3535 <maven-gpg-plugin .version>3.0.1</maven-gpg-plugin .version>
36+ <!-- jsoup 网页解析 -->
37+ <jsoup .version>1.15.3</jsoup .version>
3638 </properties >
3739
3840 <dependencies >
127129 <version >1.18.24</version >
128130 <scope >test</scope >
129131 </dependency >
132+
133+ <!-- jsoup 网页解析 -->
134+ <dependency >
135+ <groupId >org.jsoup</groupId >
136+ <artifactId >jsoup</artifactId >
137+ <version >${jsoup.version} </version >
138+ </dependency >
130139 </dependencies >
131140
132141 <licenses >
Original file line number Diff line number Diff line change 1+ package com .fengwenyi .javalib .util ;
2+
3+ import org .jsoup .Jsoup ;
4+ import org .jsoup .nodes .Document ;
5+ import org .jsoup .nodes .Element ;
6+ import org .jsoup .select .Elements ;
7+
8+ /**
9+ * Jsoup 工具类
10+ *
11+ * @author <a href="https://fengwenyi.com">Erwin Feng</a>
12+ * @since 2022-12-07
13+ */
14+ public class JsoupUtils {
15+
16+ /**
17+ * 从 html 内容中解析标题
18+ * @param html html内容
19+ * @return 标题
20+ */
21+ public static String parseTitle (String html ) {
22+ Document doc = Jsoup .parse (html );
23+ Elements elements = doc .getElementsByTag ("title" );
24+ Element element = elements .get (0 );
25+ return element .text ();
26+ }
27+
28+ }
You can’t perform that action at this time.
0 commit comments