03爬虫 爬取hfutxc成绩

 #-*- coding:utf-8 -*-
# -*- coding: utf-8 -*-
#encoding:utf-8
import urllib
import urllib2
import cookielib
import re class SDU: def __init__(self):
self.loginUrl = 'http://222.195.8.201/pass.asp'
self.gradeUrl = 'http://222.195.8.201/student/asp/Select_Success.asp'
self.cookies = cookielib.CookieJar()
self.postdata = urllib.urlencode({
'UserStyle':'student',
'user':'',
'password':'#######'
})
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookies)) def getPage(self):
request = urllib2.Request(
url = self.loginUrl,
data = self.postdata)
result = self.opener.open(request)
result = self.opener.open(self.gradeUrl)
return result.read().decode('gbk')
#打印登录内容
#print result.read().decode('gbk') def getGrades(self):
#获得本学期成绩页面
page = self.getPage()
#正则匹配
myItems = re.findall('<TR bgcolor.*?<TD>.*?</TD>.*?<TD>(.*?)</TD>.*?<TD align="center">.*?</TD>.*?<TD align="center">(.*?)</TD>.*?</TR>',page,re.S)
for item in myItems:
print item[0]+' '+item[1].strip()+' '
#self.credit.append(item[0].encode('gbk'))
#self.grades.append(item[1].encode('gbk'))
#self.getGrade() sdu = SDU()
sdu.getPage()
sdu.getGrades()
上一篇:Linux之 nginx-redis-virtualenv-mysql


下一篇:IDEA多线程调试设置