爬虫大数据 爬虫Python AI SqlPython 运维

爬取教务系统成绩

2017-04-23  本文已影响141人  有苦向瓜诉说

首先,登入了教务系统的成绩界面,获取了Cookie和User-Agent
然后发现学校的教务系统都是框架啊,然后就查看了一下js生成的框架,得到了这个链接,进入这个链接,开始了常规的爬取,然而,又有js。在这里,网页源代码获取的就是程序中获得的,而查看元素获得的是浏览器获得的。
在把浏览器获得的东西要在源码中验证一下。
其次,发现windows的命令行居然是‘gbk'模式,严重挫伤了我的积极性,最后,还是用sublime来输出这些东西吧。

# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup

url = 'http://jwxt.xidian.edu.cn/gradeLnAllAction.do?type=ln&oper=qbinfo&lnxndm=2016-2017%D1%A7%C4%EA%B5%DA%D2%BB%D1%A7%C6%DA(%C1%BD%D1%A7%C6%DA)#qb_2016-2017%E5%AD%A6%E5%B9%B4%E7%AC%AC%E4%B8%80%E5%AD%A6%E6%9C%9F(%E4%B8%A4%E5%AD%A6%E6%9C%9F)'

headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0',
    'Cookie':None  #不写出来了
}

r = requests.get(url,headers=headers)
r.encoding = r.apparent_encoding
soup = BeautifulSoup(r.text,'html.parser')
subjects = soup.select('table.titleTop2  tr.odd > td:nth-of-type(3)')
grades = soup.select('table.titleTop2  tr.odd > td > p')
for subject,grade in zip(subjects,grades):
    info = {
        'subject':subject.text.strip(),
        'grade':grade.text.strip()
    }
    print(info)

附上部分成绩:

图片.png
上一篇下一篇

猜你喜欢

热点阅读