Android开发实例-高校录取分数线应用(一)

本系列文章提供简单Android应用开发实例方法,文章步骤如下所示:

1 获取应用所需的数据源

数据源一般来源于互联网、个人搜集或者其他方式

2 应用UI设计

每个应用软件都需要有一个简单的UI设计草图,便于开发者更好的实现编码

3 应用实现

实现完整的Android应用

特此说明:本系列文章的数据源均采用互联网方式获取,仅作为示例演示


 应用介绍

提供各个高校历届的分数线录取查询功能,作为高考学子填写志愿的参考应用。

一、 找寻数据源

1 首先打开百度,输入“高校录取分数线”进行搜索,从结果列表中找寻满足自己应用需求的数据源,这里我们选择第一条数据:

高考各省市录取分数线汇总_新浪高考

2 点击进入后,我们发现中间提供了单独的高校分数线查询框
技术分享
3 点击搜索进入高校分数线单独的查询界面,并获取到我们想要找寻数据的链接
http://kaoshi.edu.sina.com.cn/collegedb/index.php?_action=more&show=more_score&provid=&wl=1&collegeid=10001

二、分析数据源

我们通过浏览器进行基本的分析,如果需要更加复杂分析,可以利用常用的抓包软件完成。
1 按F12打开浏览器的抓包界面,chrome在netword栏,IE则进入网络栏开启。
2 通过浏览器打开第一步获取到的链接http://kaoshi.edu.sina.com.cn/collegedb/index.php?_action=more&show=more_score&provid=&wl=1&collegeid=10001,并获取到抓包信息如下:
技术分享
3 通过链接界面,我们知道查询条件包括省份信息、学校信息以及文理科选择条件。
3-1 省份信息获取   
通过对Html分析,我们发现省份信息已经存在于网页中,如下所示:
        <select id="provinceSelect">
                    <option value="1" label="北京" >北京</option>
                    <option value="2" label="天津" >天津</option>
                    <option value="3" label="上海" >上海</option>
                    <option value="4" label="重庆" >重庆</option>
                    <option value="5" label="河北" >河北</option>
                    <option value="6" label="河南" >河南</option>
                    <option value="7" label="山东" >山东</option>
                    <option value="8" label="山西" >山西</option>
                    <option value="9" label="安徽" >安徽</option>
                    <option value="10" label="江西" >江西</option>
                    <option value="11" label="江苏" >江苏</option>
                    <option value="12" label="浙江" >浙江</option>
                    <option value="13" label="湖北" >湖北</option>
                    <option value="14" label="湖南" >湖南</option>
                    <option value="15" label="广东" >广东</option>
                    <option value="16" label="广西" >广西</option>
                    <option value="17" label="云南" >云南</option>
                    <option value="18" label="贵州" >贵州</option>
                    <option value="19" label="四川" >四川</option>
                    <option value="20" label="陕西" >陕西</option>
                    <option value="21" label="青海" >青海</option>
                    <option value="22" label="宁夏" >宁夏</option>
                    <option value="23" label="黑龙江" >黑龙江</option>
                    <option value="24" label="吉林" >吉林</option>
                    <option value="25" label="辽宁" >辽宁</option>
                    <option value="26" label="西藏" >西藏</option>
                    <option value="27" label="新疆" >新疆</option>
                    <option value="28" label="内蒙古" >内蒙古</option>
                    <option value="29" label="海南" >海南</option>
                    <option value="30" label="福建" >福建</option>
                    <option value="31" label="甘肃" >甘肃</option>
                    <option value="32" label="港澳台" >港澳台</option>
          </select>
3-2 文理科选择
文理科选择信息与省份信息一致,存在于Html网页中
        <select id="wl">
          <option value="1" selected="selected">文科</option>
          <option value="2" >理科</option>
          <option value="3" >综合</option>
         </select>
3-3 学校信息获取
通过分析发现学校信息不存在与Html网页中,我们找到JavaScript代码,发现学校信息存在于http://kaoshi.edu.sina.com.cn/js/collegelist_prov_index.js中,其数据格式为:school_option_key[1][‘10001‘] = ‘北京大学‘;
其中[1]代表省份id,见3-1省份信息获取中的value值;[‘10001‘]表示学校code码
我们将数据复制到txt中,并通过Ctrl+F系列替换,将学校信息转为1#10001#北京大学格式,便于我们解析使用。最终的学校数据保存格式如下:
1#10001#北京大学
1#10002#中国人民大学
1#10003#清华大学
1#10004#北京交通大学
技术分享
技术分享
3-4获取查询结果的链接
通过抓包分析,我们获取到实际查询的地址:
http://kaoshi.edu.sina.com.cn/iframe/i_collegescore.php?_action=collegescore&provid=1&collegeid=10001&wl=2&num=0
技术分享
技术分享

其中三个重要参数:provid表示省份ID,collegeid表示学校ID,wl表示文理科选择。

3-5 结果分析

3-4返回的结果为JSON格式,如下所示:

[{"id":"14847","collegeid":"10001","provid":"19","syear":"2013","wl":"2","plan":"19","score_min":"0.00","score_avg":"678.00","score_td":"0.00","score_max":"694.00","batch":"11","batch_diff":"116"},{"id":"13183","collegeid":"10001","provid":"19","syear":"2012","wl":"2","plan":"14","score_min":"640.00","score_avg":"644.00","score_td":"0.00","score_max":"655.00","batch":"11","batch_diff":"126"},{"id":"12455","collegeid":"10001","provid":"19","syear":"2011","wl":"2","plan":"25","score_min":"633.00","score_avg":"651.00","score_td":"0.00","score_max":"690.00","batch":"11","batch_diff":"132"},{"id":"10762","collegeid":"10001","provid":"19","syear":"2010","wl":"2","plan":"25","score_min":"0.00","score_avg":"633.00","score_td":"0.00","score_max":"650.00","batch":"11","batch_diff":"121"},{"id":"8360","collegeid":"10001","provid":"19","syear":"2009","wl":"2","plan":"27","score_min":"623.00","score_avg":"637.00","score_td":"0.00","score_max":"670.00","batch":"11","batch_diff":"139"},{"id":"8359","collegeid":"10001","provid":"19","syear":"2009","wl":"2","plan":"3","score_min":"616.00","score_avg":"618.00","score_td":"0.00","score_max":"620.00","batch":"01","batch_diff":""},{"id":"5693","collegeid":"10001","provid":"19","syear":"2008","wl":"2","plan":"41","score_min":"699.00","score_avg":"703.00","score_td":"0.00","score_max":"737.00","batch":"11","batch_diff":"110"},{"id":"5692","collegeid":"10001","provid":"19","syear":"2008","wl":"2","plan":"2","score_min":"697.00","score_avg":"697.00","score_td":"0.00","score_max":"697.00","batch":"01","batch_diff":""},{"id":"5242","collegeid":"10001","provid":"19","syear":"2007","wl":"2","plan":"53","score_min":"553.00","score_avg":"659.00","score_td":"0.00","score_max":"689.00","batch":"11","batch_diff":"127"},{"id":"2841","collegeid":"10001","provid":"19","syear":"2007","wl":"2","plan":"3","score_min":"656.00","score_avg":"657.00","score_td":"0.00","score_max":"661.00","batch":"01","batch_diff":""},{"id":"5305","collegeid":"10001","provid":"19","syear":"2006","wl":"2","plan":"52","score_min":"656.00","score_avg":"674.00","score_td":"0.00","score_max":"701.00","batch":"11","batch_diff":"114"},{"id":"987","collegeid":"10001","provid":"19","syear":"2006","wl":"2","plan":"3","score_min":"670.00","score_avg":"670.00","score_td":"0.00","score_max":"671.00","batch":"01","batch_diff":""},{"id":"2","collegeid":"10001","provid":"19","syear":"2005","wl":"2","plan":"57","score_min":"614.00","score_avg":"698.00","score_td":"0.00","score_max":"731.00","batch":"11","batch_diff":"103"},{"id":"5274","collegeid":"10001","provid":"19","syear":"2005","wl":"2","plan":"12","score_min":"692.00","score_avg":"695.00","score_td":"0.00","score_max":"697.00","batch":"01","batch_diff":""},{"id":"4788","collegeid":"10001","provid":"19","syear":"2004","wl":"2","plan":"0","score_min":"665.00","score_avg":"0.00","score_td":"0.00","score_max":"0.00","batch":"00","batch_diff":""},{"id":"4384","collegeid":"10001","provid":"19","syear":"2003","wl":"2","plan":"0","score_min":"604.00","score_avg":"0.00","score_td":"0.00","score_max":"0.00","batch":"00","batch_diff":""},{"id":"4009","collegeid":"10001","provid":"19","syear":"2002","wl":"2","plan":"0","score_min":"664.00","score_avg":"0.00","score_td":"0.00","score_max":"0.00","batch":"00","batch_diff":""},{"id":"3562","collegeid":"10001","provid":"19","syear":"2001","wl":"2","plan":"0","score_min":"0.00","score_avg":"652.00","score_td":"0.00","score_max":"0.00","batch":"00","batch_diff":""}]
通过与实际展示的表格信息确定各个字段的含义,通过查看原有解析JS代码,发现所有的结果字段均以Int方式处理,我们在开发中亦如此

三、保存数据

通过步骤二我们已经获取到我们所有想要的数据以及实际查询的链接和结果格式,我们把这些数据存放到Android工程里

1 将省份信息存在values.xml中,其中省份ID为item的序号+1

    <string-array name="province">
        <item>北京</item>
        <item>天津</item>
        <item>上海</item>
        <item>重庆</item>
        <item>河北</item>
        <item>河南</item>
        <item>山东</item>
        <item>山西</item>
        <item>安徽</item>
        <item>江西</item>
        <item>江苏</item>
        <item>浙江</item>
        <item>湖北</item>
        <item>湖南</item>
        <item>广东</item>
        <item>广西</item>
        <item>云南</item>
        <item>贵州</item>
        <item>四川</item>
        <item>陕西</item>
        <item>青海</item>
        <item>宁夏</item>
        <item>黑龙江</item>
        <item>吉林</item>
        <item>辽宁</item>
        <item>西藏</item>
        <item>新疆</item>
        <item>内蒙古</item>
        <item>海南</item>
        <item>福建</item>
        <item>甘肃</item>
        <item>港澳台</item>
    </string-array>
2 将文理科选择信息保存到values.xml中,其中选择值为item序号+1

   <string-array name="type">
        <item>文科</item>
        <item>理科</item>
        <item>综合</item>
    </string-array>
3 学校文件以ASCII码(可以用其他编码,本实例就采用简单的默认编码)保存,放到assert/m/data.txt文件中。

 备注:

在分析过程中,我们发现选择学校省份以及用户所在地的下拉框数据仅差一条港澳台,示例开发中忽略差异,均看成统一的省份列表



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。