首页 > 其他分享 >基于SpringBoot WebMagic爬虫爬取大乐透双色球

基于SpringBoot WebMagic爬虫爬取大乐透双色球

时间:2023-02-27 17:34:40浏览次数:162  
标签:ball SpringBoot stream List private 爬取 String import WebMagic

大乐透网页地址:https://kjh.55128.cn/dlt-history-360.htm 双色球网页地址:https://kjh.55128.cn/ssq-history-120.htm   注:程序仅用于个人兴趣爱好,不得用于商业行为,本人一概不负责   pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>dubbo-ball</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>dubbo-ball</name>
    <description>dubbo-ball</description>

    <properties>
        <java.version>1.17</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.7.3</spring-boot.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>
        <dependency>
            <groupId>us.codecraft</groupId>
            <artifactId>webmagic-core</artifactId>
            <version>0.7.5</version>
        </dependency>
        <dependency>
            <groupId>us.codecraft</groupId>
            <artifactId>webmagic-extension</artifactId>
            <version>0.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.example.ball.DubboBallApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

 

Magic.java
package com.example.ball.conf;


import com.example.ball.handle.DLTProcessor;
import com.example.ball.handle.DoubleProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Spider;

import javax.annotation.PostConstruct;

@Component
@Slf4j
public class Magic {


    @Autowired
    @Qualifier("threadPoolTaskExecutor")
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @PostConstruct
    public void processor() throws InterruptedException {
        System.out.println("================================================大乐透==========================================================");
        threadPoolTaskExecutor.execute(() -> {
            Spider spiderDLTBall = new Spider(new DLTProcessor()).addRequest(buildRequestDLT()).thread(1);
            spiderDLTBall.runAsync();
        });
        Thread.sleep(3000);
        System.out.println("\r\n\n\n\n");
        System.out.println("================================================双色球==========================================================");
        threadPoolTaskExecutor.execute(() -> {
            Spider spiderDoubleBall = new Spider(new DoubleProcessor()).addRequest(buildRequestDoubleBall()).thread(1);
            spiderDoubleBall.runAsync();
        });
    }


    private Request buildRequestDLT() {
        return new Request("https://kjh.55128.cn/dlt-history-360.htm");
    }

    private Request buildRequestDoubleBall() {
        return new Request("https://kjh.55128.cn/ssq-history-360.htm");
    }


}

 

ThreadExecutorsConf.java
package com.example.ball.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class ThreadExecutorsConf {


    /**
     * 核心线程数(默认线程数)
     */
    private static final int corePoolSize = 60;
    /**
     * 最大线程数
     */
    private static final int maxPoolSize = 1000;
    /**
     * 允许线程空闲时间(单位:默认为秒)
     */
    private static final int keepAliveTime = 100;
    /**
     * 缓冲队列数
     */
    private static final int queueCapacity = 1000;
    /**
     * 线程池名前缀
     */
    private static final String threadNamePrefix = "Thread-";


    @Bean("threadPoolTaskExecutor")
    public ThreadPoolTaskExecutor executor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSize);
        executor.setKeepAliveSeconds(keepAliveTime);
        executor.setMaxPoolSize(maxPoolSize);
        executor.setQueueCapacity(queueCapacity);
        executor.setThreadNamePrefix(threadNamePrefix);
        //设置拒绝策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
        return executor;
    }
}

 

处理算子 DLTProcessor.java 大乐透算子处理
package com.example.ball.handle;

import com.alibaba.fastjson.util.TypeUtils;
import com.example.ball.entity.DLTBall;
import com.example.ball.entity.StatisticalDLTBall;
import com.example.ball.entity.StatisticalDLTResult;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.selector.Html;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class DLTProcessor implements PageProcessor {

    private Site site;

    @Override
    public void process(Page page) {
        Html pageHtml = page.getHtml();
        String html = pageHtml.toString();
        Document document = Jsoup.parse(html);
        Elements body = document.getElementById("table").getElementsByTag("tbody").get(0).getElementsByTag("tr");
        List<DLTBall> DLTBallHistory = new ArrayList<>();
        bodyHandle(body, DLTBallHistory);
        List<DLTBall> DLTBalls3 = DLTBallHistory.subList(0, 3);
        List<DLTBall> DLTBalls5 = DLTBallHistory.subList(0, 5);
        List<DLTBall> DLTBalls8 = DLTBallHistory.subList(0, 8);
        List<DLTBall> DLTBalls10 = DLTBallHistory.subList(0, 10);
        List<DLTBall> DLTBalls20 = DLTBallHistory.subList(0, 20);
        List<DLTBall> DLTBalls30 = DLTBallHistory.subList(0, 30);
        List<DLTBall> DLTBalls45 = DLTBallHistory.subList(0, 45);
        List<DLTBall> DLTBalls60 = DLTBallHistory.subList(0, 60);
        List<DLTBall> DLTBalls90 = DLTBallHistory.subList(0, 90);
        List<DLTBall> DLTBalls120 = DLTBallHistory.subList(0, 120);
        List<DLTBall> DLTBalls360 = DLTBallHistory.subList(0, 360);

        StatisticalDLTResult statisticalDLTResult3 = statisticalResult(DLTBalls3, 3);
        StatisticalDLTResult statisticalDLTResult5 = statisticalResult(DLTBalls5, 5);
        StatisticalDLTResult statisticalDLTResult8 = statisticalResult(DLTBalls8, 8);
        StatisticalDLTResult statisticalDLTResult10 = statisticalResult(DLTBalls10, 10);
        StatisticalDLTResult statisticalDLTResult20 = statisticalResult(DLTBalls20, 20);
        StatisticalDLTResult statisticalDLTResult30 = statisticalResult(DLTBalls30, 30);
        StatisticalDLTResult statisticalDLTResult45 = statisticalResult(DLTBalls45, 45);
        StatisticalDLTResult statisticalDLTResult60 = statisticalResult(DLTBalls60, 60);
        StatisticalDLTResult statisticalDLTResult90 = statisticalResult(DLTBalls90, 90);
        StatisticalDLTResult statisticalDLTResult120 = statisticalResult(DLTBalls120, 120);
        StatisticalDLTResult statisticalDLTResult360 = statisticalResult(DLTBalls360, 360);

        StatisticalDLTBall statisticalResult = new StatisticalDLTBall(statisticalDLTResult3, statisticalDLTResult5, statisticalDLTResult8, statisticalDLTResult10, statisticalDLTResult20, statisticalDLTResult30, statisticalDLTResult45, statisticalDLTResult60, statisticalDLTResult90, statisticalDLTResult120, statisticalDLTResult360);
    }

    private static StatisticalDLTResult statisticalResult(List<DLTBall> DLTBalls, int group) {
        long redDNum = DLTBalls.stream().filter(ball -> "单".equals(ball.getRedDS())).count();
        long redSNum = DLTBalls.stream().filter(ball -> "双".equals(ball.getRedDS())).count();
        long blueDNum = DLTBalls.stream().filter(ball -> "单".equals(ball.getBlueDS())).count();
        long blueSNum = DLTBalls.stream().filter(ball -> "双".equals(ball.getBlueDS())).count();
        int redSum = DLTBalls.stream().mapToInt(ball -> TypeUtils.castToInt(ball.getRedSum())).sum();
        int blueSum = DLTBalls.stream().mapToInt(ball -> TypeUtils.castToInt(ball.getBlueSum())).sum();
        int redKDSum = DLTBalls.stream().mapToInt(ball -> TypeUtils.castToInt(ball.getRedKD())).sum();
        int blueKDSum = DLTBalls.stream().mapToInt(ball -> TypeUtils.castToInt(ball.getBlueKD())).sum();
        int redBallMinNum = DLTBalls.stream().mapToInt(ball -> ball.getRedBalls().stream().mapToInt(TypeUtils::castToInt).min().orElse(0)).min().orElse(0);
        int redBallMaxNum = DLTBalls.stream().mapToInt(ball -> ball.getRedBalls().stream().mapToInt(TypeUtils::castToInt).max().orElse(0)).max().orElse(0);
        int blueBallMinNum = DLTBalls.stream().mapToInt(ball -> ball.getBlueBalls().stream().mapToInt(TypeUtils::castToInt).min().orElse(0)).min().orElse(0);
        int blueBallMaxNum = DLTBalls.stream().mapToInt(ball -> ball.getBlueBalls().stream().mapToInt(TypeUtils::castToInt).max().orElse(0)).max().orElse(0);

        StatisticalDLTResult statisticalDLTResult = new StatisticalDLTResult();
        statisticalDLTResult.setRedContrastDS((int) redDNum + ":" + redSNum);
        statisticalDLTResult.setBlueContrastDS((int) blueDNum + ":" + blueSNum);
        statisticalDLTResult.setRedBallMiddleNum(String.valueOf(redSum / group));
        statisticalDLTResult.setBlueBallMiddleNum(String.valueOf(blueSum / group));
        statisticalDLTResult.setRedBallKDMiddleNum(String.valueOf(redKDSum / group));
        statisticalDLTResult.setBlueBallKDMiddleNum(String.valueOf(blueKDSum / group));
        statisticalDLTResult.setRedBallMinNum(String.valueOf(redBallMinNum));
        statisticalDLTResult.setRedBallMaxNum(String.valueOf(redBallMaxNum));
        statisticalDLTResult.setBlueBallMinNum(String.valueOf(blueBallMinNum));
        statisticalDLTResult.setBlueBallMaxNum(String.valueOf(blueBallMaxNum));
        System.out.println("\r\n");
        System.out.println("===========================================================大乐透近" + group + "天出球信息统计===========================================================");
        System.out.println("红球单双比:" + statisticalDLTResult.getRedContrastDS() + "  蓝球单双比:" + statisticalDLTResult.getBlueContrastDS() + "  红球中位数:" + statisticalDLTResult.getRedBallMiddleNum() + "  蓝球中位数:" + statisticalDLTResult.getBlueBallMiddleNum() + "  红球跨度中位数:" + statisticalDLTResult.getRedBallKDMiddleNum() + "  蓝球跨度中位数:" + statisticalDLTResult.getBlueBallKDMiddleNum() + "   红球最小值:" + statisticalDLTResult.getRedBallMinNum() + "  红球最大值:" + statisticalDLTResult.getRedBallMaxNum() + "  蓝球最小值:" + statisticalDLTResult.getBlueBallMinNum() + "  蓝球最大值:" + statisticalDLTResult.getBlueBallMaxNum());
        return statisticalDLTResult;
    }


    private static void bodyHandle(Elements body, List<DLTBall> DLTBallHistory) {
        body.forEach(tr -> {
            List<String> redList = new ArrayList<>();
            List<String> blueList = new ArrayList<>();
            Integer blueSum = 0;
            String blueDS;
            Elements td = tr.getElementsByTag("td");
            DLTBall.DLTBallBuilder builder = DLTBall.builder().date(td.get(0).text()).redSum(td.get(3).text()).redDS(td.get(4).text()).redJOB(td.get(5).text()).redKD(td.get(7).text());
            Elements span = td.get(2).getElementsByTag("span");
            int blueKD;
            for (int i = 0; i < 7; i++) {
                String text = span.get(i).text();
                if (i < 5) {
                    redList.add(text);
                } else {
                    Integer num = TypeUtils.castToInt(text);
                    blueSum += num;
                    blueList.add(text);
                }
            }
            if (blueSum % 2 == 0) {
                blueDS = "双";
            } else {
                blueDS = "单";
            }
            long ouNum = blueList.stream().map(TypeUtils::castToInt).filter(integer -> integer % 2 == 0).count();
            long jiNum = blueList.stream().map(TypeUtils::castToInt).filter(integer -> integer % 2 == 1).count();
            blueKD = TypeUtils.castToInt(blueList.get(1)) - TypeUtils.castToInt(blueList.get(0));
            DLTBall build = builder.redBalls(redList).blueBalls(blueList).blueSum(TypeUtils.castToString(blueSum)).blueDS(blueDS).blueJOB(jiNum + ":" + ouNum).blueKD(TypeUtils.castToString(blueKD)).build();
            System.out.println("开奖时间:" + build.getDate() + "  红:" + build.getRedBalls() + " 蓝:" + build.getBlueBalls() + "  红球sum值:" + build.getRedSum() + "  红球sum单双:" + build.getRedDS() + "  红球奇偶比:" + build.getRedJOB() + "  红球跨度:" + build.getRedKD() + "  蓝球sum值:" + build.getBlueSum() + "  蓝球sum单双:" + build.getBlueDS() + "  蓝球奇偶比:" + build.getBlueJOB() + "  蓝球跨度:" + build.getBlueKD());
            DLTBallHistory.add(build);
        });
    }


    public static void main(String[] args) {
        List<String> ad = new ArrayList<>();
        ad.add("a");
        ad.add("b");
        ad.add("c");
        System.out.println(ad);
    }


    @Override
    public Site getSite() {
        if (site == null) {
            site = Site.me().setDomain(".55128.cn").setSleepTime(1000);
        }
        return site;
    }


}

 

DoubleProcessor.java 双色球处理算子
package com.example.ball.handle;

import com.alibaba.fastjson.util.TypeUtils;
import com.example.ball.entity.SSQBall;
import com.example.ball.entity.StatisticalSSQBall;
import com.example.ball.entity.StatisticalSSQResult;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.selector.Html;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class DoubleProcessor implements PageProcessor {

    private Site site;

    @Override
    public void process(Page page) {
        Html pageHtml = page.getHtml();
        String html = pageHtml.toString();
        Document document = Jsoup.parse(html);
        Elements body = document.getElementById("table").getElementsByTag("tbody").get(0).getElementsByTag("tr");
        List<SSQBall> SSQBallHistory = new ArrayList<>();
        bodyHandle(body, SSQBallHistory);
        List<SSQBall> SSQBalls3 = SSQBallHistory.subList(0, 3);
        List<SSQBall> SSQBalls5 = SSQBallHistory.subList(0, 5);
        List<SSQBall> SSQBalls8 = SSQBallHistory.subList(0, 8);
        List<SSQBall> SSQBalls10 = SSQBallHistory.subList(0, 10);
        List<SSQBall> SSQBalls20 = SSQBallHistory.subList(0, 20);
        List<SSQBall> SSQBalls30 = SSQBallHistory.subList(0, 30);
        List<SSQBall> SSQBalls45 = SSQBallHistory.subList(0, 45);
        List<SSQBall> SSQBalls60 = SSQBallHistory.subList(0, 60);
        List<SSQBall> SSQBalls90 = SSQBallHistory.subList(0, 90);
        List<SSQBall> SSQBalls120 = SSQBallHistory.subList(0, 120);
        List<SSQBall> SSQBalls360 = SSQBallHistory.subList(0, 360);

        StatisticalSSQResult statisticalSSQResult3 = statisticalResult(SSQBalls3, 3);
        StatisticalSSQResult statisticalSSQResult5 = statisticalResult(SSQBalls5, 5);
        StatisticalSSQResult statisticalSSQResult8 = statisticalResult(SSQBalls8, 8);
        StatisticalSSQResult statisticalSSQResult10 = statisticalResult(SSQBalls10, 10);
        StatisticalSSQResult statisticalSSQResult20 = statisticalResult(SSQBalls20, 20);
        StatisticalSSQResult statisticalSSQResult30 = statisticalResult(SSQBalls30, 30);
        StatisticalSSQResult statisticalSSQResult45 = statisticalResult(SSQBalls45, 45);
        StatisticalSSQResult statisticalSSQResult60 = statisticalResult(SSQBalls60, 60);
        StatisticalSSQResult statisticalSSQResult90 = statisticalResult(SSQBalls90, 90);
        StatisticalSSQResult statisticalSSQResult120 = statisticalResult(SSQBalls120, 120);
        StatisticalSSQResult statisticalSSQResult360 = statisticalResult(SSQBalls360, 360);

        StatisticalSSQBall statisticalResult = new StatisticalSSQBall(statisticalSSQResult3, statisticalSSQResult5, statisticalSSQResult8, statisticalSSQResult10, statisticalSSQResult20, statisticalSSQResult30, statisticalSSQResult45, statisticalSSQResult60, statisticalSSQResult90, statisticalSSQResult120, statisticalSSQResult360);
    }

    private static StatisticalSSQResult statisticalResult(List<SSQBall> SSQBalls, int group) {
        long redDNum = SSQBalls.stream().filter(ball -> "单".equals(ball.getRedDS())).count();
        long redSNum = SSQBalls.stream().filter(ball -> "双".equals(ball.getRedDS())).count();
        long blueDNum = SSQBalls.stream().filter(ball -> "单".equals(ball.getBlueDS())).count();
        long blueSNum = SSQBalls.stream().filter(ball -> "双".equals(ball.getBlueDS())).count();
        int redSum = SSQBalls.stream().mapToInt(ball -> TypeUtils.castToInt(ball.getRedSum())).sum();
        int blueSum = SSQBalls.stream().mapToInt(ball -> TypeUtils.castToInt(ball.getBlueSum())).sum();
        int redKDSum = SSQBalls.stream().mapToInt(ball -> TypeUtils.castToInt(ball.getRedKD())).sum();
        int blueKDSum = SSQBalls.stream().mapToInt(ball -> TypeUtils.castToInt(ball.getBlueKD())).sum();
        int redBallMinNum = SSQBalls.stream().mapToInt(ball -> ball.getRedBalls().stream().mapToInt(TypeUtils::castToInt).min().orElse(0)).min().orElse(0);
        int redBallMaxNum = SSQBalls.stream().mapToInt(ball -> ball.getRedBalls().stream().mapToInt(TypeUtils::castToInt).max().orElse(0)).max().orElse(0);
        int blueBallMinNum = SSQBalls.stream().mapToInt(ball -> ball.getBlueBalls().stream().mapToInt(TypeUtils::castToInt).min().orElse(0)).min().orElse(0);
        int blueBallMaxNum = SSQBalls.stream().mapToInt(ball -> ball.getBlueBalls().stream().mapToInt(TypeUtils::castToInt).max().orElse(0)).max().orElse(0);

        StatisticalSSQResult statisticalSSQResult = new StatisticalSSQResult();
        statisticalSSQResult.setRedContrastDS((int) redDNum + ":" + redSNum);
        statisticalSSQResult.setBlueContrastDS((int) blueDNum + ":" + blueSNum);
        statisticalSSQResult.setRedBallMiddleNum(String.valueOf(redSum / group));
        statisticalSSQResult.setBlueBallMiddleNum(String.valueOf(blueSum / group));
        statisticalSSQResult.setRedBallKDMiddleNum(String.valueOf(redKDSum / group));
        statisticalSSQResult.setBlueBallKDMiddleNum(String.valueOf(blueKDSum / group));
        statisticalSSQResult.setRedBallMinNum(String.valueOf(redBallMinNum));
        statisticalSSQResult.setRedBallMaxNum(String.valueOf(redBallMaxNum));
        statisticalSSQResult.setBlueBallMinNum(String.valueOf(blueBallMinNum));
        statisticalSSQResult.setBlueBallMaxNum(String.valueOf(blueBallMaxNum));
        System.out.println("\r\n");
        System.out.println("===========================================================双色球近" + group + "天出球信息统计===========================================================");
        System.out.println("红球单双比:" + statisticalSSQResult.getRedContrastDS() + "  蓝球单双比:" + statisticalSSQResult.getBlueContrastDS() + "  红球中位数:" + statisticalSSQResult.getRedBallMiddleNum() + "  蓝球中位数:" + statisticalSSQResult.getBlueBallMiddleNum() + "  红球跨度中位数:" + statisticalSSQResult.getRedBallKDMiddleNum() + "  蓝球跨度中位数:" + statisticalSSQResult.getBlueBallKDMiddleNum() + "   红球最小值:" + statisticalSSQResult.getRedBallMinNum() + "  红球最大值:" + statisticalSSQResult.getRedBallMaxNum() + "  蓝球最小值:" + statisticalSSQResult.getBlueBallMinNum() + "  蓝球最大值:" + statisticalSSQResult.getBlueBallMaxNum());
        return statisticalSSQResult;
    }


    private static void bodyHandle(Elements body, List<SSQBall> SSQBallHistory) {
        body.forEach(tr -> {
            List<String> redList = new ArrayList<>();
            List<String> blueList = new ArrayList<>();
            Integer blueSum = 0;
            String blueDS;
            Elements td = tr.getElementsByTag("td");
            SSQBall.SSQBallBuilder builder = SSQBall.builder().date(td.get(0).text()).redSum(td.get(4).text()).redDS(td.get(5).text()).redJOB(td.get(6).text()).redKD(td.get(9).text());
            Elements span = td.get(2).getElementsByTag("span");
            int blueKD;
            for (int i = 0; i < 7; i++) {
                String text = span.get(i).text();
                if (i < 6) {
                    redList.add(text);
                } else {
                    Integer num = TypeUtils.castToInt(text);
                    blueSum += num;
                    blueList.add(text);
                }
            }
            if (blueSum % 2 == 0) {
                blueDS = "双";
            } else {
                blueDS = "单";
            }
            long ouNum = blueList.stream().map(TypeUtils::castToInt).filter(integer -> integer % 2 == 0).count();
            long jiNum = blueList.stream().map(TypeUtils::castToInt).filter(integer -> integer % 2 == 1).count();
            SSQBall build = builder.redBalls(redList).blueBalls(blueList).blueSum(TypeUtils.castToString(blueSum)).blueDS(blueDS).blueJOB(jiNum + ":" + ouNum).blueKD(TypeUtils.castToString(blueList.get(0))).build();
            System.out.println("开奖时间:" + build.getDate() + "  红:" + build.getRedBalls() + " 蓝:" + build.getBlueBalls() + "  红球sum值:" + build.getRedSum() + "  红球sum单双:" + build.getRedDS() + "  红球奇偶比:" + build.getRedJOB() + "  红球跨度:" + build.getRedKD() + "  蓝球sum值:" + build.getBlueSum() + "  蓝球sum单双:" + build.getBlueDS() + "  蓝球奇偶比:" + build.getBlueJOB() + "  蓝球跨度:" + build.getBlueKD());
            SSQBallHistory.add(build);
        });
    }


    @Override
    public Site getSite() {
        if (site == null) {
            site = Site.me().setDomain(".55128.cn").setSleepTime(1000);
        }
        return site;
    }


}

 

 

实体类 DLTBall.java
package com.example.ball.entity;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class DLTBall implements Serializable {

    private String date;

    private List<String> redBalls;

    private List<String> blueBalls;

    //红色sum
    private String redSum;

    //红色sum值单双
    private String redDS;

    //红色奇偶比
    private String redJOB;

    //红色跨度
    private String redKD;

    //蓝色sum
    private String blueSum;

    //蓝色sum值单双
    private String blueDS;

    //蓝色奇偶比
    private String blueJOB;

    //蓝色跨度
    private String blueKD;


}

 

SSQBall.java
package com.example.ball.entity;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SSQBall implements Serializable {

    private String date;

    private List<String> redBalls;

    private List<String> blueBalls;

    //红色sum
    private String redSum;

    //红色sum值单双
    private String redDS;

    //红色奇偶比
    private String redJOB;

    //红色跨度
    private String redKD;

    //蓝色sum
    private String blueSum;

    //蓝色sum值单双
    private String blueDS;

    //蓝色奇偶比
    private String blueJOB;

    //蓝色跨度
    private String blueKD;


}

 

StatisticalDLTBall.java
package com.example.ball.entity;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class StatisticalDLTBall implements Serializable {

    private StatisticalDLTResult statisticalDLTResult3;
    private StatisticalDLTResult statisticalDLTResult5;
    private StatisticalDLTResult statisticalDLTResult8;
    private StatisticalDLTResult statisticalDLTResult10;
    private StatisticalDLTResult statisticalDLTResult20;
    private StatisticalDLTResult statisticalDLTResult30;
    private StatisticalDLTResult statisticalDLTResult45;
    private StatisticalDLTResult statisticalDLTResult60;
    private StatisticalDLTResult statisticalDLTResult90;
    private StatisticalDLTResult statisticalDLTResult120;
    private StatisticalDLTResult statisticalDLTResult360;

}

 

StatisticalDLTResult.java
package com.example.ball.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class StatisticalDLTResult implements Serializable {

    //红球单双比
    private String redContrastDS;

    //蓝球单双比
    private String blueContrastDS;

    //红球中位数
    private String redBallMiddleNum;

    //蓝球中位数
    private String BlueBallMiddleNum;

    //红球跨度中位数
    private String redBallKDMiddleNum;

    //蓝球跨度中位数
    private String blueBallKDMiddleNum;

    //红球最小值
    private String redBallMinNum;

    //红球最大值
    private String redBallMaxNum;

    //蓝球最小值
    private String blueBallMinNum;

    //蓝球最大值
    private String blueBallMaxNum;


}

 

StatisticalSSQBall.java
package com.example.ball.entity;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class StatisticalSSQBall implements Serializable {

    private StatisticalSSQResult statisticalSSQResult3;
    private StatisticalSSQResult statisticalSSQResult5;
    private StatisticalSSQResult statisticalSSQResult8;
    private StatisticalSSQResult statisticalSSQResult10;
    private StatisticalSSQResult statisticalSSQResult20;
    private StatisticalSSQResult statisticalSSQResult30;
    private StatisticalSSQResult statisticalSSQResult45;
    private StatisticalSSQResult statisticalSSQResult60;
    private StatisticalSSQResult statisticalSSQResult90;
    private StatisticalSSQResult statisticalSSQResult120;
    private StatisticalSSQResult statisticalSSQResult360;

}

 

StatisticalSSQResult.java
package com.example.ball.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class StatisticalSSQResult implements Serializable {

    //红球单双比
    private String redContrastDS;

    //蓝球单双比
    private String blueContrastDS;

    //红球中位数
    private String redBallMiddleNum;

    //蓝球中位数
    private String BlueBallMiddleNum;

    //红球跨度中位数
    private String redBallKDMiddleNum;

    //蓝球跨度中位数
    private String blueBallKDMiddleNum;

    //红球最小值
    private String redBallMinNum;

    //红球最大值
    private String redBallMaxNum;

    //蓝球最小值
    private String blueBallMinNum;

    //蓝球最大值
    private String blueBallMaxNum;


}

 

标签:ball,SpringBoot,stream,List,private,爬取,String,import,WebMagic
From: https://www.cnblogs.com/lockyluo/p/17160574.html

相关文章

  • SpringBoot项目打包部署
    转载自:https://blog.csdn.net/yw_2022/article/details/122649955========= SpringBoot项目打包在linux服务器中运行:jar类型项目会打成jar包:jar类型项目使用SpringBoo......
  • java netty socket实例:报文长度+报文内容,springboot
    前言说实话,javanetty方面的资料不算多,尤其是自定义报文格式的,少之又少自己写了个简单的收发:报文长度+报文内容发送的话,没有写自动组装格式,自己看需求吧,需要的话,自己完......
  • WebMagic
    原文链接:CSDN@qq_44885775#WebMagicWebMagic官网:Introduction·WebMagicDocumentsGitHub-WebMagicIntroduction·WebMagicDocuments4.7配置代理·WebMagi......
  • SpringBoot中对拦截器和过滤器的理解
    1、两者的关系   2、过滤器的使用步骤实现Filter接口,并加上@WebFilter注解@Slf4j//filterName为该过滤器的名称;//urlPatterns对哪些url进行拦截@WebFil......
  • springboot修改事务隔离级别
       【SpringBoot】事务的隔离级别、Spring的事务传播机制_51CTO博客_springboot事务隔离级别......
  • SpringBoot移除liquibase
    SpringBoot移除liquibase1、spring自动加载配置的jar:org.springframework.boot:spring-boot-autoconfigure:2.3.2.RELEASE在spring-boot-autoconfigure包中查找spring.......
  • rabbitmq的启动命令和springboot整合使用rabbitmq
    环境:windows安装erlang和rabbitmq的过程这里不多说,记得两个的版本要对应。1.启动rabbitmq:进入sbin目录:其中可能报错:则需要终止已经开始的进程(可能是之前启动过)tasklist|......
  • SpringBoot多数据源以及事务处理
    背景在高并发的项目中,单数据库已无法承载大数据量的访问,因此需要使用多个数据库进行对数据的读写分离,此外就是在微服化的今天,我们在项目中可能采用各种不同存储,因此也需要......
  • 总结SpringBoot1.x迁移到2.x需要注意的问题
    SpringBoot1.x和SpringBoot2.x版本差异化还是比较大的,有些三方依赖组件有些是基于2.0版本为标准升级的,当我们将项目由1.0升级到2.0时会出现依赖的方法不存在或方法错误......
  • zxk-logs_springboot集成redis
    pom.xml:<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><gro......