宝宝起名工具类

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

截图如下:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

焱童鞋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值