爬取教务系统课程表

import bs4
import requests
from PIL import Image
from io import BytesIO
import json
url = [' http://urp.hebau.edu.cn:9001','http://urp.hebau.edu.cn:9002',
       'http://urp.hebau.edu.cn:9003','http://urp.hebau.edu.cn:9004',
        'http://urp.hebau.edu.cn:9005','http://urp.hebau.edu.cn/']
session = requests.session()
header = {}
def Yzm(i):
    global header
    header={
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'Host': url[i].split("//")[1],
        'Origin': 'http://urp.hebau.edu.cn:9003',
        'Referer': 'http://urp.hebau.edu.cn:9003/loginAction.do',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36'
        }
    return session.get(url=url[i] + '/loginAction.do',headers=header)
a = 2
YZM_URL = Yzm(a)
cookie = YZM_URL.headers['Set-Cookie']
cookie = cookie.strip('; path=/')
yzm_url = 'http://urp.hebau.edu.cn:9003/validateCodeAction.do?random='
YZM_Header = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'Host': url[0].split("//")[1],
        'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Connection': 'keep-alive',
        'Origin': 'http://urp.hebau.edu.cn:9003',
        'Referer': 'http://urp.hebau.edu.cn:9003/loginAction.do',
        'cookie': cookie,
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36'
}
#print(YZM_URL.text)
yzmdata = session.get(yzm_url,headers=YZM_Header)
tempIm = BytesIO(yzmdata.content)
im = Image.open(tempIm)
im.show()
yzm = input("请输入验证码:")
usename = input("请输入账号:")
password = input("请输入账号:")
postdata = {
    "zjh":usename,
    "mm":password,
    'v_yzm':yzm
}
header['cookie'] =cookie
login = session.post(url=url[a] + '/loginAction.do',data=postdata,headers=header)
#print(login.text)
KCB_header=YZM_Header
KCB_header['Referer'] += '/menu/menu.jsp '
print(KCB_header)
CSC_url = url[a] + '/xkAction.do?actionType=6'
CSC = session.get(url=CSC_url,headers=KCB_header)
print(CSC.text)
Kb = bs4.BeautifulSoup(CSC.text,'lxml')
with open("laopo.txt",'w',encoding='utf-8') as f:
    f.write(CSC.text)





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值