模拟登录爬取广职院正方教务系统

最近突然的想爬取学校的课程表,于是经过几经努力,终于出来的一个小demo,话不多说,马上为大家讲解:先放上代码

import re
import requests
from fake_useragent import UserAgent
from pyquery import PyQuery as pq
from school_api.check_code import CHECK_CODE

class GDSchool(object):
    def __init__(self):
        self.ua=UserAgent()  #用于随机浏览器头
        self.headers={
            'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
            'Accept-Language':'Accept-Language',
            'Host':'61.142.209.20:9090',
            'Accept-Encoding':'gzip, deflate',
            'UserAgent':self.ua.random
                      }
        self.number='*******'#input('请输入学号:')          测试的时候我是直接输入了学号与密码
        self.password='**********'#input('请输入密码:')

    def responseMenu(self,data): #获取菜单链接
        html=pq(data.text)
        mainItems = {}
        menu=html('#headDiv > ul li').items()
        for subItems in menu:
            sub_nextItems = {}
            for nextItems in  subItems('ul li a').items():
                subList = []
                sub_nextItems[nextItems.text()]=nextItems.attr('href')
                subList.append(sub_nextItems)
            mainItems[subItems('.top_link').text()]=subList
        return mainItems

    def resonseImage(self): #用于获取验证码并识别验证码,返回验证码
        try:
            response=self.rssions.get('http://61.142.209.20:9090/CheckCode.aspx',stream=True)
            code=CHECK_CODE.verify(response.content)
            # with open(code+'.gif','wb') as fp:
            #     fp.write(response.content)
            return code
        except Exception as 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值