#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'<b>(.+?)</b>',r.content.decode("utf-8"))
print(t[0])
print(t[1])
python接口测试登陆jenkins代码
最新推荐文章于 2024-05-27 14:07:49 发布
本文介绍使用Python的requests库进行网站登录的方法,包括设置请求头、构造POST数据及利用正则表达式解析返回内容。通过具体示例展示如何实现自动化登录流程,并从响应中提取所需信息。
3200

被折叠的 条评论
为什么被折叠?



