拿走直接用
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.5.15</version>
</dependency>
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
public class BaiDuHot {
public static void main(String[] args) throws IOException {
String URL="https://top.baidu.com/board?tab=realtime";
Document doc= Jsoup.connect(URL).get();
Elements elements = doc.select("div[class=category-wrap_iQLoo horizontal_1eKyQ]");
JSONArray BaiDuHotList = new JSONArray();
for (Element element : elements) {
JSONObject BaiDuHot = new JSONObject();
BaiDuHot.put("title",element.select("div[class=c-single-text-ellipsis]").text());
BaiDuHot.put("link",element.select("a[class=title_dIF3B]").attr("href"));
BaiDuHot.put("hot_value",element.select("div[class=hot-index_1Bl1a]").text());
BaiDuHotList.add(BaiDuHot);
}
System.out.println(BaiDuHotList);
}
}