无聊学了点PY,随便写了点

起因是准备手术住院,计划断网,得找个机器人帮我每天登校内省得那个天杀的“连续登录”没了。就抄了个原来Google Map Mobile火星纠偏API的HTTP POST范例,改一下,放到了crontab里,就OK了。

晚上LQ给我打电话要我给他弄份潢川今年高考录取结果,无条件答应,于是决定不用三年前php的代码,就拿这个学py。上chinaunix找了份py的tutorial看了遍,然后就开始码——毛主席说学一种语言的最好办法就是用它码字。。。

然后折腾了几个小时。。直接贴最后的代码。。功能神马的不解释。。

#!/usr/bin/python
# -*- coding: gbk -*-
import urllib2
import re
url = 'http://125.46.28.141/datacenter/pages/PZLQueryResult.aspx'
ubound, lbound = 750, 455
r = open('like.out.txt', 'r')
w = open('like.out.2.txt', 'w')
w.write(r.readline()[0:-1] + '\n')
l = r.readline()
while l:
	l = l[0:-1]
	a = l.split(',')
	ksh = a[0]
	xm = a[1]
	bmxh = a[2]
	zf = int(a[13])
	lqjg = a[14]
	f, s, m, jg = None, '', None, ''
	if not lqjg and zf >= lbound:
		data = '__VIEWSTATE=%2FwEPDwULLTE2MTg3Nzg0OTZkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBQhzYm5RdWVyeb%2F%2B%2F7Ev4dQnl2IdoZQ6VtBR4yO2&__EVENTVALIDATION=%2FwEWBQL835iOAwKn4%2BXICwK047EHAqnjjcUHAoCT5K4FuWUHByXv5c5MLSXNY5ShVHo1Z20%3D&txtZKZH=' + ksh + '&txtSFZH=&txtBMXH=' + bmxh + '&sbnQuery.x=47&sbnQuery.y=13'
		while not s:
			try:
				f = urllib2.urlopen(url, data)
				s = f.read()
				f.close()
			except:
				pass
		m = re.search(r'[.\n]*录取院校.*nbsp;(\(.*)</td></tr></table></p>[.\n]*', s)
		if m:
			jg = m.group(1).strip()
		print ksh, xm, zf, jg
	w.write(l + jg + '\n')
	l = r.readline()
r.close()
w.close()

Leave a Reply

Your email address will not be published. Required fields are marked *