zoukankan      html  css  js  c++  java
  • 通过fsockopen()方法从中国福彩网获取双色球历史中奖数据

    # 以下代码基于 CI 框架 #

    public function history_draw($page = 0)
    {
        set_time_limit(0);
    
        $page++;
        $up2now = date('Y-m-d');
        $fp = fsockopen('www.cwl.gov.cn', 80, $errno, $errstr, 60) or die('fsockopen失败:' . $errno . $errstr);
        $out = <<<EOL
    GET http://www.cwl.gov.cn/cwl_admin/kjxx/findDrawNotice?name=ssq&issueCount=&issueStart=&issueEnd=&dayStart=2003-01-01&dayEnd={$up2now}&pageNo={$page} HTTP/1.1
    Host: www.cwl.gov.cn
    Connection: keep-alive
    Accept: application/json, text/javascript, */*; q=0.01
    X-Requested-With: XMLHttpRequest
    User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    Referer: http://www.cwl.gov.cn/kjxx/ssq/kjgg/
    Accept-Encoding: gzip, deflate, sdch
    Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
    Cookie: UniqueID=3dauCXLoQK01tDVH1575514942401; Sites=_21; 21_vq=6; _ga=GA1.3.1090297853.1575514946; _gid=GA1.3.447342718.1575514946; _Jo0OQK=4A1B07EC59D1342CFCAA246B2A0002154A53049E0E5B207A6D0A66050057CE12B9F70A1581661090506815D462089F11972544962C45EF0BF16418257266B0B3233F1B3C19C5B2FC5F8E6E66EDA7420CD4BE6E66EDA7420CD4BD84331FADDCD4DAC3328EEBACF9E4A3CGJ1Z1fQ==
    
    
    
    EOL;
    
        fwrite($fp, $out);
        $data = '';
        while (!feof($fp)) {
            $data .= fgets($fp, 128);
        }
        fclose($fp);
    
        $result     = substr($data, strpos($data, '{'));
        $result     = json_decode($result, true);
        $records    = $result['countNum'];
        $total_page = $result['pageCount'];
    
        if ($page > $total_page) {
            exit('数据写入完成');
        }
    
        foreach ($result['result'] as $value) {
            $red = explode(',', $value['red']);
            $new[] = array(
                'issue'     => $value['code'],
                'draw_date' => substr($value['date'], 0, 10),
                'blue'         => $value['blue'],
                'red_1'     => $red[0],
                'red_2'     => $red[1],
                'red_3'     => $red[2],
                'red_4'     => $red[3],
                'red_5'     => $red[4],
                'red_6'     => $red[5],
            );
        }
        $this->db->insert_batch('dual_ball', $new);
    
        echo '2003-01-01 至 '. $up2now . ' 总开奖期数为:' . $records .',已插入' . count($new);
        echo '<br>';
    
        if ($total_page > 1) {
            sleep(1);
            $this->history_draw($page);
        }
    }

    SQL文件下载:

    https://files.cnblogs.com/files/gentsir/dual_ball.zip

  • 相关阅读:
    ArcGIS for window mobile 数据打开
    Linux学习拾遗
    ArcEngine 连接sql server sde
    Server Objects Extension(SOE)开发(三)
    Server Objects Extension(SOE)开发(二)
    C# 调用ArcGIS server admin api
    切片文件发布成切片服务
    Printing tools 自定义模板打印的实现
    ubuntu下安装matlab
    修改ubuntu中的gcc和g++版本
  • 原文地址:https://www.cnblogs.com/gentsir/p/10842621.html
Copyright © 2011-2022 走看看