python 模拟登录

import requests
import json
def GetCookie():
    s=requests.session()
    loginUrl='http://wapjin.com/index.php/home/admin/'
    postData={'pass':'111.2.19.13'}
    rs=s.post(loginUrl,postData)
    c=requests.cookies.RequestsCookieJar()#利用RequestsCookieJar获取
    c.set('cookie-name','cookie-value')
    s.cookies.update(c)
    return s.cookies.get_dict()
headers = {
    'Content-Type': 'application/json;charset=utf-8',
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0"

}
data = {
'pass': '111.2.19.13'


}
#     data = json.dumps(data)
s = requests.session()
url = 'http://wapjin.com/index.php/home/admin/admin.html'
headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
}
cookies = GetCookie()  # 这里就是利用上面的函数获得的Cookies
rs = s.get(url, headers=headers, cookies=cookies, verify=True)
rs.encoding = 'utf-8'
print(rs.text)

评论

刷新

友情链接