python 爬虫 处理超级课程表传输的数据

news/2024/7/19 10:09:45 标签: python, 爬虫, json

借鉴的别人的思路

http://www.oschina.net/code/snippet_2463131_53711

抓取超级课程表传输的数据

他的传输数据居然是明文的……

现在已经把自己的课表都抓出来了

不过这个也是抓取手机APP数据的思路?

还是值得学习一番的。

//很蠢……

//我干嘛不直接爬学校的教务处呢

#!/usr/local/bin/python2.7
# -*- coding: utf8 -*-
"""
  超级课程表话题抓取
"""
import urllib2
from cookielib import CookieJar
import json


''' 读Json数据 '''
def fetch_data(json_data):
    data = json_data['data']
    timestampLong = data['timestampLong']
    messageBO = data['messageBOs']
    topicList = []
    for each in messageBO:
        topicDict = {}
        if each.get('content', False):
            topicDict['content'] = each['content']
            topicDict['schoolName'] = each['schoolName']
            topicDict['messageId'] = each['messageId']
            topicDict['gender'] = each['studentBO']['gender']
            topicDict['time'] = each['issueTime']
            print each['schoolName'],each['content']
            topicList.append(topicDict)
    return timestampLong, topicList


''' 加载更多 '''
def load(timestamp, headers, url):
    headers['Content-Length'] = '159'
    loadData = 'timestamp=%s&phoneBrand=Meizu&platform=1&genderType=-1&topicId=19&phoneVersion=16&selectType=3&channel=MXMarket&phoneModel=M040&versionNumber=7.2.1&' % timestamp
    req = urllib2.Request(url, loadData, headers)
    loadResult = opener.open(req).read()
    loginStatus = json.loads(loadResult).get('status', False)
    if loginStatus == 1:
        print 'load successful!'
        timestamp, topicList = fetch_data(json.loads(loadResult))
        load(timestamp, headers, url)
    else:
        print 'load fail'
        print loadResult
        return False

loginUrl = 'http://120.55.151.61/V2/StudentSkip/loginCheckV4.action'
topicUrl = 'http://120.55.151.61/V2/Treehole/Message/getMessageByTopicIdV3.action'
classUrl = 'http://120.55.151.61/V2/Course/getCourseTableFromSchool3.action'
headers = {
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'User-Agent': 'Dalvik/1.6.0 (Linux; U; Android 4.1.1; M040 Build/JRO03H)',
    'Host': '120.55.151.61',
    'Connection': 'Keep-Alive',
    'Accept-Encoding': 'gzip',
    'Content-Length': '207',
    }

''' ---登录部分--- '''
loginData = 'phoneBrand=Meizu&platform=1&deviceCode=868033014919494&account=4B027B0DFA04DD9D7796FDC3A1282427&phoneVersion=16&password=BC892A42D928A7E026F147FC140C4300&channel=MXMarket&phoneModel=M040&versionNumber=7.2.1&'
cookieJar = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))
req = urllib2.Request(loginUrl, loginData, headers)
loginResult = opener.open(req).read()
loginStatus = json.loads(loginResult).get('data', False)
if loginResult:
    print 'login successful!'
else:
    print 'login fail'
    print loginResult

"""

''' ---获取话题--- '''
topicData = 'timestamp=0&phoneBrand=Meizu&platform=1&genderType=-1&topicId=19&phoneVersion=16&selectType=3&channel=MXMarket&phoneModel=M040&versionNumber=7.2.1&'
headers['Content-Length'] = '147'
topicRequest = urllib2.Request(topicUrl, topicData, headers)
topicHtml = opener.open(topicRequest).read()
topicJson = json.loads(topicHtml)
topicStatus = topicJson.get('status', False)
print topicJson
if topicStatus == 1:
    print 'fetch topic success!'
    timestamp, topicList = fetch_data(topicJson)
    load(timestamp, headers, topicUrl)
"""

# 这儿是获取课表
ClassData = ' phoneVersion=16&phoneBrand=Meizu&platform=1&parameters=%7B%22crawlType%22%3A0%2C%22hasVerCode%22%3Afalse%2C%22maxCount%22%3A0%2C%22parameterList%22%3A%5B%7B%22key%22%3A%22para1%22%2C%22question%22%3A0%2C%22type%22%3A1%2C%22value%22%3A%2279F07E42A30275BD1D1132BAE11C8408%22%7D%2C%7B%22key%22%3A%22para2%22%2C%22question%22%3A0%2C%22type%22%3A2%2C%22value%22%3A%2276D704007FF11CFD551D1B94662A2D66%22%7D%2C%7B%22key%22%3A%22pama3%22%2C%22question%22%3A0%2C%22type%22%3A3%2C%22value%22%3A%22bks%22%7D%5D%2C%22semester%22%3A%221%22%2C%22startSchoolYear%22%3A%222016%22%2C%22step%22%3A1%2C%22verCodeError%22%3Afalse%7D&channel=MXMarket&phoneModel=M040&versionNumber=7.2.1&'
headers['Content-Length'] = '667'
ClassRequest = urllib2.Request(classUrl, ClassData, headers)
ClassHtml = opener.open(ClassRequest).read()
ClassJson = json.loads(ClassHtml)
ClassStatus = ClassJson.get('status', False)
print ClassJson

转载于:https://www.cnblogs.com/qscqesze/p/5605576.html


http://www.niftyadmin.cn/n/534121.html

相关文章

Mysql动态创建表

该项目是快递项目&#xff0c;因为快递每天的收发快递数量是很多的&#xff0c;所以如果所有数据都存放到一张表中的话&#xff0c;时间长了就会造成表的臃肿。因此需要动态创建表。 sql语句的写法&#xff1a; <select id "creatTable"> create table ${n…

Backbone.js实战之模型集合学习笔记

关于这两天遇到的代码没有找到PHP页面&#xff0c;或者有跨域的问题&#xff1b; 解决方案&#xff1a; 1.在本机中安装PHP开发环璄&#xff0c;并可以执行PHP代码的页面&#xff1b;2.将HTML页与PHP放置在同一个文件夹中&#xff0c;否则会有跨域问题&#xff1b;3.将HTML页与…

Mysql根据条件批量更新动态数据

当表字段需要根据id进行更新的时候&#xff0c;如果有多条数据需要根据对应的id更新&#xff0c;那么就可以考虑动态更新。 假设需要更新表中的state状态字段&#xff0c;以及需要根据对应的id更新表中的number字段。直接上代码 java代码部分&#xff1a;写java代码部分是为了…

二级菜单延迟隐藏

最近碰到一个需求&#xff0c;因为在IE8下&#xff0c;左侧2级导航因为滚动条挡住3级菜单&#xff0c;导致不能选中 思索了下&#xff0c;参考QQ的头像简介功能写了个延迟操作&#xff0c;解决了这个问题 var timer null;$(".xj-third-li").hover(function(){clearT…

Mysql查询每个月的最后一天

如果数据库表中有涉及到金额的部分&#xff0c;很多时候都需要查询每个月最后一天数据。该语句是用来查询每个月最后一天的。 sql语句的写法&#xff1a; <select id "selectLastDayEachMonth" parameterType "hashmap" resultMap "BaseResul…

Linux_Struct file()结构体

struct file结构体定义在/linux/include/linux/fs.h(Linux 2.6.11内核)中&#xff0c;其原型是&#xff1a;struct file { /* * fu_list becomes invalid after file_free is called and queued via * fu_rcuhead for RCU freeing */ un…

Mysql向动态表中插入数据

向动态表中插入数据,其中表名称是动态的&#xff0c;需要通过map集合进行传参。需要插入的数据时通过list封装的实体类&#xff0c;然后把list集合放入到map中作为参数传递。 sql语句的写法&#xff1a; <insert id "insertData" parameterType "hashmap…

java基础—面向对象

目录 一、面向过程的思想和面向对象的思想 二、简单理解面向对象 三、面向对象的设计思想 四、对象和类的概念 五、如何抽象出一个类&#xff1f; 六、类&#xff08;对象&#xff09;之间的关系 七、Java与面向对象 八、为什么使用面向对象编程&#xff1f; 一、面向过程的思想…