登录形势与政策(简单,提交表单就行,没有其他东西)

简单的登录

import requests

url = "http://101.76.160.231/eol/homepage/course/courseblock/login.jsp"

header = {
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'
}

form = {
    'courseId':'13780',
    '_style':'default',
    'IPT_LOGINUSERNAME':'账号',
    'IPT_LOGINPASSWORD':'密码',
}
data = requests.post(url,  headers=header, data=form)
print(data.text)

用session来记录cookies,维持登录状态

import requests

url = "http://101.76.160.231/eol/homepage/course/courseblock/login.jsp"  #提交登录表单的网址
url1 = "http://101.76.160.231/eol/homepage/course/layout/page/index.jsp?courseId=13780"     #未登录之前和登录之后的网址
s = requests.Session()

header = {
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'
}

form = {
    'courseId':'13780',
    '_style':'default',
    'IPT_LOGINUSERNAME':'账号',
    'IPT_LOGINPASSWORD':'密码',
}
data = s.post(url,  headers=header, data=form)
data1 = s.get(url1,  headers=header, data=form)
print(data1.text)

你可能感兴趣的:(登录形势与政策(简单,提交表单就行,没有其他东西))