宝宝起名工具类

  宝宝起名太麻烦,使用如下工具类选择大于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 {
                // 解析 HTML
                Document 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>

截图如下:

猜你喜欢

转载自blog.csdn.net/u012440725/article/details/131826277