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

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