Python爬虫登录西电教务处查询成绩

十一月 15th, 2012 by admin

cookie = cookielib.cookiejar()headers = {user-agent: mozilla/5.0 (windows; u; windows nt 6.1; en-us; rv:1.9.1.6) gecko/20091201 firefox/3.5.6,referer: http://202.117.120.37/xdjwwebnew/index.jsp}opener = urllib2.build_opener(urllib2.httpcookieprocessor(cookie))urllib2.install_opener(opener)#获取sharedvalueinputnum = raw_input(请输入你的学号:)inputpas = raw_input(请输入你的密码:)req = urllib2.request(http://202.117.120.37/xdjwwebnew/index.jsp, headers=headers)page = urllib2.urlopen(req).read()pattern = re.compile((?=var sharedvalue = )-{0,1}d+)sharedvalue = re.findall(pattern, page)pas1 = hashlib.md5(inputpas).hexdigest() + sharedvalue[0]password = hashlib.md5(pas1).hexdigest()#制作postdatapostdata = urllib.urlencode({uid:inputnum,password: password,slttype: 学 生,submit: 确 定,command: studentlogin})req = urllib2.request(http://202.117.120.37/xdjwwebnew/servlet/userscontrol,data=postdata,headers=headers)result = opener.open(req).read()testreq = urllib2.request(http://202.117.120.37/xdjwwebnew/studentstatus/queryscore/query_person_score.jsp,headers=headers)result = opener.open(testreq).read().decode(gbk)pattern = tr.*?.*?div.*?div.*?div.*?(.*?)/div.*?div.*?div.*?div.*?div.*?(.*?)/div.*?/trlist = re.findall(pattern,result,re.s)list1 = []list2 = []for items in list:list1.append(items[0].strip().encode(utf-8))list2.append(items[1].strip().encode(utf-8))lista = list1[2:]listb = list2[2:]print 你的成绩如下:newdict = dict(zip(lista,listb))for (k,v) in newdict.items():print %s : %s%(k,v)


相关阅读:

相关分类:

随机阅读: