编码以下:#!/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: , Welcome to Drop by.
“””
#查看联接
cet = “=” band “id=” exam_id
print “Connecting…”
#结构HTTP头
header = {‘Referer’:’’}
#第二个主要参数出現则应用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)文章内容来源于:www.seo-7.comwww.sEo-6.comhttp://www.seo-6.com/seoyh/seojichurm/118335.html
(编辑:部分内容来互联网)