依赖
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
package ai.wincloud.dapp.common.util;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
/**
* @author cy
*/
public class HtmlUtil {
public static String getHtml(String html) {
// HtmlUtil.
return ";";
}
public static void main(String[] args) {
try {
// 连接到网页
Document document = Jsoup.connect("https://bscscan.com/tx/0x604eefe23e37e6d57c38360c6a23a34be574bb1d37eb2f100c411015b4650d24").get();
// 获取指定的HTML标签内容
Element element = document.select("span#spanTxHash").first();
if (element != null) {
String hash = element.text();
System.out.println("hash: " + hash);
}
Element elementTime = document.select("span#showUtcLocalDate").first();
String time = elementTime.attr("data-timestamp");
Element elementStatus = document.select("div.col.col-md-9 span.badge.bg-success").first();
String status = elementStatus.text();
Element elementFrom = document.select("div.row.mb-4 div.col-md-9 div span.me-1 a").last();
String from = elementFrom.text();
Element elementTo = document.select("span.d-flex.align-items-center span.d-inline").first();
String to = elementTo.text();
Element elementMoney = document.select(".d-flex.flex-wrap.align-items-center span.me-1").first();
String money = elementMoney.getElementsByAttribute("2").text();
System.out.println("content: " + money);
} catch (Exception e) {
e.printStackTrace();
}
}
}