Python实现CET查分的方法
2019/7/13 21:34:12
本文主要是介绍Python实现CET查分的方法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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)
# -*- 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实现CET查分的方法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享
- 2024-12-19使用python 把docx转为pdf文件有哪些方法?-icode9专业技术文章分享
- 2024-12-19python怎么更换换pip的源镜像?-icode9专业技术文章分享
- 2024-12-19Python资料:新手入门的全面指南
- 2024-12-19Python股票自动化交易实战入门教程
- 2024-12-19Python股票自动化交易入门教程
- 2024-12-18Python量化入门教程:轻松掌握量化交易基础知识