2016年12月19日 星期一 晴

今天获悉SS获得环亚太杯数学一等奖,比较高兴,花了十几二十分钟把他们班同学的成绩查询出来了,发现基本参加的都有奖。我只能说,要么这个奖跟数学大王一样水,要么他们班继承了明珠的光荣传统。情况究竟是哪种,明年四大杯见分晓。

环亚太杯成绩查询的参考代码如下,改一下名字就能查到了:

[code] #! /usr/bin/env python #coding=utf-8

import urllib2, urllib, cookielib,socket import re, time, json, random import os from urlparse import urlparse

def get_url_data(url,headers = None): request = urllib2.Request(url) if headers: request.add_header(‘User-Agent’, headers)

nFail = 0
while nFail < 5:
    try:
        sock = urllib2.urlopen(request)
        rsp = sock.read()
        sock.close()
        return rsp
    except Exception,e:
        nFail += 1
        print "get_url_data fail:%s count=%d,Exception=%s" % (url,nFail,e)
        time.sleep(5)
print "get url fail:%s" % (url)
return None

students = [u’李白’,u’杜甫’,]

result_str = ‘’’(.*?)’’’ result_obj = re.compile(result_str,re.M | re.DOTALL)

def main(): global USR,PSW socket.setdefaulttimeout(120)#

baseurl = 'http://www.duxiebeisai.com/index.php?r=%2Fsearch%2Findex&tbid=4&_csrf=UUMuSXJMZEFkLGQ8PhsNJGgxFjNFAD0vECF5OCM7I3crBBclQHlddw%3D%3D&xm=3&keywords='
#baseurl = 'http://www.duxiebeisai.com/index.php?r=%2Fsearch%2Findex&tbid=4&_csrf=amhKWHN1UjQFLQ0fATI1UjwJHygKPGcZHF0kLyZAFXs8D38ROxYbfA%3D%3D&xm=6&keywords='
cj = urllib2.HTTPCookieProcessor(cookielib.CookieJar())
openner = urllib2.build_opener(cj)
urllib2.install_opener(openner)

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0',
            'Host':'ww.duxiebeisai.com',
            'Cookie':'_csrf=1118ca3f837270e5c07d16d449bcb39efc5841f66c8676695bb0472d56aa80bfa%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22Hwh2qMK6rbL27HM-dlo75aIoN-uMPIYc%22%3B%7D',
            'Connection':'keep-alive',
            'Accept-Language':'	en-US,en;q=0.5',
            'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            }

result = []
for st in students:
    url = baseurl + urllib.quote(st.encode('utf-8'))
    rsp = get_url_data(url,headers)
    if rsp:
        objs = result_obj.findall(rsp)
        if objs:
            print st
            result.extend(objs[1:])
            result.append('\n')

with open('mz.txt','w') as f:
    f.write(''.join(result))

if name == ‘main’: main()

[/code]