Python实现CET查分的方法
作者:Sephiroth 时间:2023-06-13 12:05:51
Python CET自动查询方法需要用到的python方法模块有:sys、urllib2
本文实例讲述了Python实现CET查分的方法。分享给大家供大家参考。具体实现方法如下:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys, urllib2
def CetQuery(band, exam_id):
"""CETQuery version 0.2 2009.2.28
An Exercise Program by PT, GZ University
Author Blog: http://apt-blog.co.cc , Welcome to Drop by.
"""
#查询连接
cet = "http://cet.99sushe.com/cetscore_99sushe0902.html?t=" + band + "&id=" + exam_id
print "Connecting..."
#构造HTTP头
header = {'Referer':'http://cet.99sushe.com/'}
#第二个参数出现则使用post方式提交
req = urllib2.Request(cet, '', header)
try:
data = urllib2.urlopen(req).read()
except BaseException, e:
print "Error retrieving data:", e
return -1
if not len(result):
print "Error Occured. Maybe record not existed."
return -1
#解码字符串
result = data.decode("gb2312").encode("utf8")
res_tu = tuple(result.split(','))
score_tu = ("听力", "阅读", "综合", "写作", "总分", "学校", "姓名")
print "n***** CET %s 成绩清单 *****" % (band)
print "-准考证号: %s" % (exam_id)
for i in range(7):
print "-%s: %s" % (score_tu, res_tu)
print "**************************n"
print "准考证号前一位同学: %sn后两位同学分别是: %s、%s" % (res_tu[-3], res_tu[-2], res_tu[-1])
return 0
if __name__ == "__main__":
if (len(sys.argv) != 3) or
(sys.argv[1] != '4' and sys.argv[1] != '6') or
(len(sys.argv[2]) != 15):
print "Error: 程序参数错误,考试类型(4、6),准考证号长度(15位)"
print "nExample:nnCETQuery.py 4 123456789012345nn"
print CetQuery.__doc__
sys.exit(1)
statue = CetQuery(sys.argv[1], sys.argv[2])
sys.exit(statue)
希望本文所述对大家的Python程序设计有所帮助。
标签:Python,方法
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python发送邮件实现基础解析
2022-01-28 10:33:22
Go语言中Goroutine的设置方式
2024-05-13 10:40:43
![](https://img.aspxhome.com/file/2023/9/125119_0s.png)
解决Keras 中加入lambda层无法正常载入模型问题
2022-02-21 03:41:11
JavaScript奇怪的比较——隐式类型转换
2009-02-15 13:06:00
python threading和multiprocessing模块基本用法实例分析
2021-08-13 04:23:49
opencv+python实现鼠标点击图像,输出该点的RGB和HSV值
2023-05-16 13:37:20
![](https://img.aspxhome.com/file/2023/1/69471_0s.jpg)
详解MySQL从入门到放弃-安装
2024-01-12 16:24:50
![](https://img.aspxhome.com/file/2023/3/122893_0s.png)
网页表单项Input的高级限制级用法
2008-10-27 16:50:00
python数据结构的排序算法
2021-03-11 04:04:10
![](https://img.aspxhome.com/file/2023/0/78800_0s.png)
python实现数通设备tftp备份配置文件示例
2022-12-02 13:59:21
python中matplotlib的颜色及线条控制的示例
2023-11-04 08:11:50
![](https://img.aspxhome.com/file/2023/5/111985_0s.png)
python实现将元祖转换成数组的方法
2022-11-22 02:40:32
MySQL表LEFT JOIN左连接与RIGHT JOIN右连接的实例教程
2024-01-24 05:14:17
![](https://img.aspxhome.com/file/2023/0/93060_0s.png)
mysql 不等于 符号写法
2024-01-22 07:03:06
玩转CSS3色彩[译]
2010-01-13 13:02:00
![](https://img.aspxhome.com/file/UploadPic/20101/13/01-80s.jpg)
Python实战使用Selenium爬取网页数据
2021-06-18 19:11:56
asp 批量删除选中的多条记录
2011-03-29 10:33:00
![](https://img.aspxhome.com/file/UploadPic/20112/5/201125112326166.gif)
使用Python程序计算钢琴88个键的音高
2021-12-24 06:46:31
![](https://img.aspxhome.com/file/2023/9/109469_0s.jpg)
Python的几种主动结束程序方式
2022-10-12 14:39:25
![](https://img.aspxhome.com/file/2023/6/97766_0s.jpg)
GoLang切片并发安全解决方案详解
2024-05-09 09:54:15