标签:inf decode 运行 .com 打开 png info odi submit
上一篇cookie绕过验证码模拟登录博客园,但这只是第一步,一般登录后,还会有其它的操作,如发帖,评论等等,这时候如何保持会话呢?
1、通过help方法查看帮助文档,截图一部分,后面省略了,有兴趣的自己可以敲一下看看
2、参考代码
1 # coding:utf-8 2 import requests 3 help(requests.session())
1、使用session登录只需在登录的基础上稍做修改,即可
2、参考代码
# coding:utf-8 import requests # 先打开登录首页,获取部分session url = "http://localhost:8080/jenkins/j_acegi_security_check" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0" } # get方法其它加个ser-Agent就可以了 d = {"j_username": "admin", "j_password": "111111", "from": "", "Submit": u"登录", "remember_me": "on" } s = requests.session() r = s.post(url, headers=headers, data=d) #print (r.content.decode(‘utf-8‘))
1、先打开新建任务,手动输入任务名称和选择下边选项后,打开fiddler抓包,然后点击“确定”
fiddler抓包
2、把body的参数内容写成字典格式
参考代码:
1 body = {"name":"北京-宏哥1", 2 "mode": "hudson.model.FreeStyleProject", 3 "Jenkins-Crumb":"51a97fc7fbf3792823230d9bdd7ec906", 4 "json":{"name":"北京-宏哥1", 5 "mode": "hudson.model.FreeStyleProject", 6 "Jenkins-Crumb":"51a97fc7fbf3792823230d9bdd7ec906" 7 8 } 9 }
3、用上面登录保存的session继续发送post请求,来新建任务
4、执行后,查看所有任务就多了一条新增的了
5、运行结果部分截图:
6、粘贴到记事本修改后缀查看:
1 # coding:utf-8 2 import requests 3 # 先打开登录首页,获取部分session 4 url = "http://localhost:8080/jenkins/j_acegi_security_check" 5 headers = { 6 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0" 7 } # get方法其它加个ser-Agent就可以了 8 d = {"j_username": "admin", 9 "j_password": "111111", 10 "from": "", 11 "Submit": u"登录", 12 "remember_me": "on" 13 } 14 15 s = requests.session() 16 r = s.post(url, headers=headers, data=d) 17 #print (r.content.decode(‘utf-8‘)) 18 # 正则表达式提取账号和登录按钮 19 import re 20 t = re.findall(r‘<b>(.+?)</b>‘, r.content.decode(‘utf-8‘)) # 用python3的这里r.content需要解码 21 print (t[0]) 22 print (t[1]) 23 #新建任务 24 url1 = "http://localhost:8080/jenkins/createItem" 25 body = {"name":"北京-宏哥1", 26 "mode": "hudson.model.FreeStyleProject", 27 "Jenkins-Crumb":"51a97fc7fbf3792823230d9bdd7ec906", 28 "json":{"name":"北京-宏哥1", 29 "mode": "hudson.model.FreeStyleProject", 30 "Jenkins-Crumb":"51a97fc7fbf3792823230d9bdd7ec906" 31 32 } 33 } 34 35 r2 = s.post(url1, data=body, verify=False) 36 print (r2.content.decode(‘utf-8‘))
这里我是用新建任务写的案例,小伙伴可以试下Jenkins里边其他的关联接口
小伙伴都看到了吧,session关联接口就是这么简单!!!赶快动起来吧。
python接口自动化(十四)--session关联接口(详解)
标签:inf decode 运行 .com 打开 png info odi submit
原文地址:https://www.cnblogs.com/du-hong/p/10648716.html