最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

Python實(shí)現(xiàn)CET查分的方法

來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-27 14:40:17
文檔

Python實(shí)現(xiàn)CET查分的方法

Python實(shí)現(xiàn)CET查分的方法:本文實(shí)例講述了Python實(shí)現(xiàn)CET查分的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下: 代碼如下:#!/usr/bin/python # -*- coding: utf-8 -*- import sys, urllib2 def CetQuery(band, exam_id): CETQuery versio
推薦度:
導(dǎo)讀Python實(shí)現(xiàn)CET查分的方法:本文實(shí)例講述了Python實(shí)現(xiàn)CET查分的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下: 代碼如下:#!/usr/bin/python # -*- coding: utf-8 -*- import sys, urllib2 def CetQuery(band, exam_id): CETQuery versio

本文實(shí)例講述了Python實(shí)現(xiàn)CET查分的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

代碼如下:

#!/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..."
#構(gòu)造HTTP頭
header = {'Referer':'http://cet.99sushe.com/'}
#第二個參數(shù)出現(xiàn)則使用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 = ("聽力", "閱讀", "綜合", "寫作", "總分", "學(xué)校", "姓名")
print "n***** CET %s 成績清單 *****" % (band)
print "-準(zhǔn)考證號: %s" % (exam_id)
for i in range(7):
print "-%s: %s" % (score_tu, res_tu)
print "**************************n"
print "準(zhǔn)考證號前一位同學(xué): %sn后兩位同學(xué)分別是: %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: 程序參數(shù)錯誤,考試類型(4、6),準(zhǔn)考證號長度(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程序設(shè)計(jì)有所幫助。

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

Python實(shí)現(xiàn)CET查分的方法

Python實(shí)現(xiàn)CET查分的方法:本文實(shí)例講述了Python實(shí)現(xiàn)CET查分的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下: 代碼如下:#!/usr/bin/python # -*- coding: utf-8 -*- import sys, urllib2 def CetQuery(band, exam_id): CETQuery versio
推薦度:
標(biāo)簽: 方法 查分 python
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top