宝宝起名太麻烦,使用如下工具类选择大于96分的名字
public static void main(String[] args) {Integer pages = 50;for (int i = 1; i <= pages; i++) {//楚辞起名String chuCiUrl = "https://www.mamahaoyun.com/qiming/xingdeng/nvhai/shulong/chuci/?page=" + i;//诗经起名String shiJingUrl = "https://www.mamahaoyun.com/qiming/xingdeng/nvhai/shulong/shijing/?page=" + i;//唐诗起名String tangShiUrl = "https://www.mamahaoyun.com/qiming/xingdeng/nvhai/shulong/tangshi/?page=" + i;//中庸起名String zhongYongUrl = "https://www.mamahaoyun.com/qiming/xingdeng/nvhai/shulong/zhongyong/?page=" + i;//宋词起名String songCiUrl = "https://www.mamahaoyun.com/qiming/xingdeng/nvhai/shulong/songci/?page=" + i;//辞赋起名String ciFuUrl = "https://www.mamahaoyun.com/qiming/xingdeng/nvhai/shulong/cifu/?page=" + i;//论语起名String lunYuUrl = "https://www.mamahaoyun.com/qiming/xingdeng/nvhai/shulong/lunyu/?page=" + i;//孟子起名String mengZiUrl = "https://www.mamahaoyun.com/qiming/xingdeng/nvhai/shulong/mengzi/?page=" + i;// 发送请求HttpResponse response = HttpRequest.get(chuCiUrl).header("Accept", "*/*").execute();String html = response.body();try {// 解析 HTMLDocument doc = Jsoup.parse(html);// 获取指定 div 的元素列表Elements divs = doc.getElementsByTag("div");for (Element div : divs) {if (div.hasAttr("class") && div.attr("class").equals("font_number")) {// 获取姓名和评分Element name = div.selectFirst("h2.name_font_img");Element score = div.selectFirst("div.name_list_score:nth-child(1) > span");// 输出结果String tempName = name.text();String tempSoc = score.text();String soc = tempSoc.replaceAll("分", "");if (Integer.parseInt(soc) >= 96) {System.out.println("姓名:" + tempName + " 分数:" + tempSoc);}}}} catch (Exception e) {e.printStackTrace();}}
导入hutools和 jsoup依赖
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.6.2</version> </dependency>
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup --> <dependency><groupId>org.jsoup</groupId><artifactId>jsoup</artifactId><version>1.16.1</version> </dependency>
截图如下: