试手登录了下我们学校的研究生信息管理系统,自动计算学分绩点

 # -*- coding:utf-8 -*-
import urllib
import urllib2
import re
import cookielib
from bs4 import BeautifulSoup class OUC:
def __init__(self,username,password):
self.loginUrl = "http://graduate.ouc.edu.cn/j_acegi_security_check"
# self.leftFrameUrl = "http://graduate.ouc.edu.cn/listLeft.do?"
self.frameGradeUrl = "http://graduate.ouc.edu.cn/accessModule.do?moduleId=25011&groupId="
# self.gradeUrl = "http://graduate.ouc.edu.cn/listMyBulletin.do?"
self.cookies = cookielib.CookieJar()
self.postdata = urllib.urlencode({
'j_username':username,
'j_password':password,
'groupId':''
})
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookies)) def getPage(self):
user_agent = 'Mozilla/4.0(compatible;MSIE 5.5;Windows NT)'
headers = {'User-Agent':user_agent}
request = urllib2.Request(
url=self.loginUrl,
data=self.postdata,
headers=headers
)
result = self.opener.open(request)
gradeResult = self.opener.open(self.frameGradeUrl)
btfsp = BeautifulSoup(gradeResult.read())
# print btfsp.prettify() content = btfsp.body.find_all("tr")
resultTable = [[0 for col in range(3)] for row in range(14)]
print u'专业名称'.rjust(15),'\t',u'成绩','\t',u'学分'
i = 0
for item in content[1:]:
itemList = item.find_all("td")
classname = itemList[1].text.split(' ')[0].strip()
score = itemList[6].text.split('\n')[7].strip()
weight = itemList[7].text
resultTable[i][0] = classname
resultTable[i][1] = float(score)
resultTable[i][2] = float(weight)
print classname.rjust(15),'\t',score.rjust(3),'\t',weight.rjust(3)
i += 1
# print '%10s' % classname,'%-3s' % score.split('\n')[7],'\t',weight
# 计算GPA
sumGPA = 0
sumWeight = 0
for k in range(14):
sumWeight += resultTable[k][2]
sumGPA += resultTable[k][1] * resultTable[k][2]
gpa = sumGPA / sumWeight print u'\n学分绩点为:',gpa if __name__ == '__main__':
# ouc_stu = OUC()
print '================ Welcome ===================='
print u'Please enter your login messages:'
username = input('username:')
password = input('password:')
print u'Waiting...'
ouc_stu = OUC(username,password)
ouc_stu.getPage()

原文地址:http://www.cnblogs.com/leonwen/p/5730874.html

Python爬取信息管理系统计算学分绩点的更多相关文章

  1. Python 爬取美女图片,分目录多级存储

    最近有个需求:下载https://mm.meiji2.com/网站的图片. 所以简单研究了一下爬虫. 在此整理一下结果,一为自己记录,二给后人一些方向. 爬取结果如图:   整体研究周期 2-3 天, ...

  2. 没有内涵段子可以刷了,利用Python爬取段友之家贴吧图片和小视频(含源码)

    由于最新的视频整顿风波,内涵段子APP被迫关闭,广大段友无家可归,但是最近发现了一个"段友"的app,版本更新也挺快,正在号召广大段友回家,如下图,有兴趣的可以下载看看(ps:我不 ...

  3. 萌新学习Python爬取B站弹幕+R语言分词demo说明

    代码地址如下:http://www.demodashi.com/demo/11578.html 一.写在前面 之前在简书首页看到了Python爬虫的介绍,于是就想着爬取B站弹幕并绘制词云,因此有了这样 ...

  4. Python 爬取淘宝商品数据挖掘分析实战

    Python 爬取淘宝商品数据挖掘分析实战 项目内容 本案例选择>> 商品类目:沙发: 数量:共100页  4400个商品: 筛选条件:天猫.销量从高到低.价格500元以上. 爬取淘宝商品 ...

  5. Python 爬取 热词并进行分类数据分析-[解释修复+热词引用]

    日期:2020.02.02 博客期:141 星期日 [本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)] 所有相关跳转: a.[简单准备] b.[云图制作+数据导入] c.[拓扑 ...

  6. 教你用python爬取抖音app视频

    记录一下如何用python爬取app数据,本文以爬取抖音视频app为例. 编程工具:pycharm app抓包工具:mitmproxy app自动化工具:appium 运行环境:windows10 思 ...

  7. 用Python爬取分析【某东618】畅销商品销量数据,带你看看大家都喜欢买什么!

    618购物节,辰哥准备分析一波购物节大家都喜欢买什么?本文以某东为例,Python爬取618活动的畅销商品数据,并进行数据清洗,最后以可视化的方式从不同角度去了解畅销商品中,名列前茅的商品是哪些?销售 ...

  8. Python爬取《你好李焕英》豆瓣短评并基于SnowNLP做情感分析

    爬取过程在这里: Python爬取你好李焕英豆瓣短评并利用stylecloud制作更酷炫的词云图 本文基于前文爬取生成的douban.txt,基于SnowNLP做情感分析. 依赖库: 豆瓣镜像比较快: ...

  9. Python爬取 | 唯美女生图片

    这里只是代码展示,且复制后不能直接运行,需要配置一些设置才行,具体请查看下方链接介绍: Python爬取 | 唯美女生图片 from selenium import webdriver from fa ...

随机推荐

  1. The trap of Bash trap

    Can you spot the problem with the following Bash script? resource_created="false" function ...

  2. html公用头部和尾部

    这个方式比较简单,样式和js也有效果,还有object和iframe方式 效果图,可以看出公共的样式对于引入的文件也有效果,在加载完文件后js也是有效果的 index.html header.html ...

  3. 瓜子IM智能客服系统的数据架构设计(整理自现场演讲)

    本文由ITPub根据封宇在[第十届中国系统架构师大会(SACC2018)]现场演讲内容整理而成. 1.引言 瓜子业务重线下,用户网上看车.预约到店.成交等许多环节都发生在线下.瓜子IM智能客服系统的目 ...

  4. CPU参数指标说明

    %user %user表示CPU一共花了多少比例的时间运行在用户态空间或者说是用户进程(running user space processes) 典型的用户态空间程序有:Shells.数据库.web ...

  5. 07-selenium、PhantomJS(无头浏览器)

    selenium(自动化测试工具可用于在爬虫中解决js动态加载问题) 简介(本质就是模仿浏览器工作) Selenium 是什么?一句话,自动化测试工具.它支持各种浏览器,包括 Chrome,Safar ...

  6. Springboot整合单元测试

    概述 对于简单易懂的小项目而言,可以不适用单元测试对平时开发没有什么影响,但是对于大型项目,单纯的依赖 “手点功能测试”, 那简直就是灾难,好了,说道这里,应该明白测试的一个重要性了,,,接下来,我们 ...

  7. 使用Redis实现最近N条数据的决策

    前言 很多时候,我们会根据用户最近一段时间的行为,做出一些相应的策略,从而改变系统的运动轨迹. 举个简单的例子来说明一下: 假设A公司现在有两个合作伙伴(B和C),B和C都是提供天气数据的,现在A公司 ...

  8. python3的reload(sys)

    import sys reload(sys) sys.setdefaultencoding(‘utf-8’) 以上是python2的写法,但是在python3中这个需要已经不存在了,这么做也不会什么实 ...

  9. Html 页面底部添加版权信息

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. Java 日期处理类

    日期处理类 Date类 当前日期时间 java.util.Date import java.util.Date; public class TestDemo { public static void ...