python接口测试登陆jenkins代码

#coding:utf-8
import requests
import re

url="http://localhost:8080/j_acegi_security_check"
headers={
"Connection": "keep-alive",
"Content-Length": "xx",
"Cache-Control": "xx",
"Origin": "http://localhost:8000",
"Upgrade-Insecure-Requests":"xx" ,
"Content-Type":"application/x-www-form-urlencoded",
"User-Agent": "xxxx",
"Accept":"xxx",
"Referer": "http://localhost:8000/login?from=%2F",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cookie": "xxxxx"

}
data={
    "j_username":"xxx",
    "j_password":"xxxx",
    "from":"",
    "remember_me":"on",
    "Submit":"Sign in"
}

r=requests.post(url,headers=headers,data=data)
print(r.content)
print(r.status_code)

#正则表达式提取账号和登陆按钮
t=re.findall(r'(.+?)',r.content.decode("utf-8"))
print(t[0])
print(t[1])

你可能感兴趣的:(requests)