Python implements CET detection and pythoncet Detection
This example describes how to implement CET scoring in Python. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is as follows :#! /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.
"""
# Querying connections
Cet = "http://cet.99sushe.com/cetscore_99sushe0902.html? T = "+ band +" & id = "+ exam_id
Print "Connecting ..."
# Construct an HTTP Header
Header = {'Referer': 'http: // cet.99sushe.com /'}
# Use post to submit the second parameter
Req = urllib2.Request (cet, '', header)
Try:
Data = urllib2.urlopen (req). read ()
Except t BaseException, e:
Print "Error retrieving data:", e
Return-1
If not len (result ):
Print "Error Occured. Maybe record not existed ."
Return-1
# Decoding string
Result = data. decode ("gb2312"). encode ("utf8 ")
Res_tu = tuple (result. split (','))
Score_tu = ("hearing", "reading", "Comprehensive", "writing", "total score", "school", "name ")
Print "n ***** CET % s Score list *****" % (band)
Print "-Admission Ticket No.: % s" % (exam_id)
For I in range (7 ):
Print "-% s: % s" % (score_tu, res_tu)
Print "*************************** n"
Print "Admission Ticket number previous student: % sn the last two students are: % 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: program parameter Error, test type (4, 6), admission ticket number length (15 digits )"
Print "nExample: nnCETQuery. py 4 123456789012345nn"
Print CetQuery. _ doc __
Sys. exit (1)
Statue = CetQuery (sys. argv [1], sys. argv [2])
Sys. exit (statue)
I hope this article will help you with Python programming.