Skip to content

Instantly share code, notes, and snippets.

@messense
Created August 21, 2012 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save messense/3413978 to your computer and use it in GitHub Desktop.
Save messense/3413978 to your computer and use it in GitHub Desktop.
CET四六级自动猜测准考证号
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import re
import sys
def main():
print("===========================================")
print("Welcome to run this CET score query program")
print(" Created by messense<http://messense.me>")
print("===========================================\n\n")
code = raw_input("Please type the first 10 number of your ID(like 6100111211): ")
start_room = int(raw_input("Please type 3 number of starting exam room(like 001): "))
stop_room = int(raw_input("Please type 3 number of ending exam room(like 100): "))
seats = int(raw_input("Please type the count of people of one room(like 30): "))
name = unicode(raw_input("Please type your name: "), "gb2312").encode("utf-8")
print("Query name is %s" % urllib2.quote(name))
url = "http://www.chsi.com.cn/cet/query?zkzh=%s&xm=%s"
current_room = start_room
current_room_str = ''
while current_room <= stop_room:
if current_room < 10:
current_room_str = '00' + str(current_room)
elif current_room >= 10 and current_room < 100:
current_room_str = '0' + str(current_room)
else:
current_room_str = str(current_room)
current_seat = 1
current_seat_str = ''
while current_seat <= seats:
if current_seat < 10:
current_seat_str = '0' + str(current_seat)
else:
current_seat_str = str(current_seat)
num = "%s%s%s" % (code, current_room_str, current_seat_str)
query_url = url % (num, urllib2.quote(name))
print("Now querying ID %s" % num)
try:
req = urllib2.Request(query_url)
req.add_header("Referer", "http://www.chsi.com.cn/cet/")
html = urllib2.urlopen(req).read()
except:
print("Open query url(%s) error" % query_url)
continue
if html.find('cetTable') == -1:
print("Can not find your score, try next.")
current_seat += 1
else:
print("\n\nWow! I've found your score!")
print("Your ID is %s" % num)
print("Please open http://www.chsi.com.cn/cet/ with your browser then type the ID and your name to view your CET score.")
sys.exit(1)
current_room += 1
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment