博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 爬虫 处理超级课程表传输的数据
阅读量:5119 次
发布时间:2019-06-13

本文共 4117 字,大约阅读时间需要 13 分钟。

借鉴的别人的思路

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

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

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

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

还是值得学习一番的。

//很蠢……

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

#!/usr/local/bin/python2.7# -*- coding: utf8 -*-"""  超级课程表话题抓取"""import urllib2from cookielib import CookieJarimport 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 FalseloginUrl = '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 topicJsonif 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

你可能感兴趣的文章
python 3.0 学习
查看>>
20162308 2016-2017-2 《程序设计与数据结构》第2周学习总结
查看>>
【GoLang】golang 报管理工具 Godep 介绍
查看>>
卫生部专家:一天吃6个含铬胶囊没事 不要恐慌
查看>>
Spring 工具包
查看>>
华为交换机以 LACP 模式实现链路聚合
查看>>
django xlwt实现资产导出功能
查看>>
开博说明
查看>>
【转载】OpenWrt sysupgrade 命令行更新固件到最新版
查看>>
计算机基础
查看>>
servlet基础
查看>>
rsync排除多个文件实现同步
查看>>
【Linux】- ps -ef |grep 命令
查看>>
bzoj 1584 Cleaning Up 打扫卫生 dp
查看>>
Python_shelve模块
查看>>
from __future__ import print_function的使用
查看>>
两台电脑直接共享文件
查看>>
[bzoj4827][Hnoi2017]礼物_FFT
查看>>
[bzoj1926][Sdoi2010]粟粟的书架_二分_主席树
查看>>
[bzoj4154][Ipsc2015]Generating Synergy_KD-Tree_dfs序
查看>>