环境搭建
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
代码实现
public static void readHTML(String html) {
//解析htmlurl路径
//URL u = new URL(url);
//Document doc = Jsoup.parse(u, 0);
//解析html字符串
Document doc = Jsoup.parse(html);
//下面的代码基本与js相同
Element span = doc.getElementById("a1");
System.out.println(span.text());
}