The example of this article is about Python's method of achieving CET checking. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code 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 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 The record is not existed.
Return-1
#解码字符串
result = Data.decode ("gb2312"). Encode ("UTF8")
Res_tu = tuple (Result.split (', '))
Score_tu = ("Listening", "reading", "Synthesis", "writing", "Total Score", "school", "name")
Print "n***** CET%s Performance List * * *"% (band)
Print "-Ticket number:%s"% (exam_id)
For I in range (7):
Print "-%s:%s"% (Score_tu, res_tu)
Print "**************************n"
Print "Ticket number before a classmate:%SN after 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 errors, test type (4, 6), ticket number Length (15)"
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 your Python programming.