Python网络爬虫(7)西南科技大学统一认证平台登录

import requests
from http.cookiejar import CookieJar
from bs4 import BeautifulSoup

urlBefore = "http://cas.swust.edu.cn/authserver/login"

def getResopnseAfterLogin():
    head ={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36",
    }
    s = requests.Session()
    s.cookies = CookieJar()
    r1 = s.get(urlBefore,headers = head)
    bsObj1 = BeautifulSoup(r1.text,"html.parser")
    #请求登录的页面
    lt = bsObj1.find("input",{"name":"lt"})["value"]
    execution = bsObj1.find("input",{"name":"execution"})["value"]
    #获取网页的流水号
    #print(lt)
    #print(execution)
    params = {
        'username':'你的学号',
        'password':'你的密码',
        'lt':lt,
        'dllt':'userNamePasswordLogin',
        'execution':execution,
        '_eventId':'submit',
        'rmShown':'1'
        }
    #构造提交的数据包
    r2 = s.post(urlBefore,data = params,headers = head)
    #提交数据包
    r3 = s.get(urlBefore)
    #获取登陆后的页面
    bsObj2 = BeautifulSoup(r3.text,"html.parser")
    print(bsObj2)
        
getResopnseAfterLogin()

起初打算进入教务管理系统,但是始终不能达成,于是转而进入主要系统

http://www.cnblogs.com/wzxwhd/p/5966563.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章