request redirection
# encoding:utf-8
import re
import json
import random
from esdapi.config import BASE_URL
from requests.sessions import Session
class Ad09(object):
def __init__(self):
"""
初始化session 并设置header和cookie
"""
self.url = "http://xxxx/ad09/index"
self.s = Session()
self.s.headers.setdefault("Content_type", "application/x-www-form-urlencoded")
self.s.headers.update(Referer="http://172.21.2.3:8009/ad09")
self.s.cookies.update(self.get_cookies(self.url)[0])
# self.s.headers.update({"Cookies": self.get_cookies()})
def get_cookies(self,url):
"""
获取上一次请求的cookie
:return: 返回cookie dict
"""
r = self.s.get(url)
print(r.cookies.get_dict())
return (r.cookies.get_dict(), r.text)
def get_token(self):
"""
获取上一次请求隐匿的表单token
:return:
"""
pattern = 'name="__RequestVerificationToken" type="hidden" value="(.*)"'
p = re.compile(pattern)
text = self.get_cookies(self.url)[1]
if p.search(text):
token = p.search(text).groups()[0]
token = token.__str__().strip('"')
else:
return
return token
def get_mobile(self):
s = "144"
n = range(10)
for i in range(8):
s += random.choice(n).__str__()
if len(s) == 4 and s == "1442":
s = (int(s) - 1).__str__()
print(s)
return s
def Ad09_index(self):
param = {"__RequestVerificationToken": self.get_token(),
"FromPage": "ZaEsd-Ad09-",
"FromSE": "",
"CustomerId": "",
"ProductType": "all",
"Amounts": 50000,
"LoanTerm": 24,
"Name": u"测试",
"Mobile": self.get_mobile(),
"Province": "31b25d9c-912d-4db9-82ab-10d87a2885b3",
"City": "92ce2049-36bf-4ae6-b831-22359c38f337",
"hiddenLoanPurpose": 0,
"hiddenLoanPurposeDetail": "{8132707A-E2AE-4F58-85FC-F023277D845B}"}
r = self.s.post(self.url, data=param, allow_redirects=False)
print("Location url is:", r.headers["Location"])
try:
return (r.headers["Location"], json.loads(r.text))
except:
return (r.headers["Location"], r.text)
def get_Estimate(self):
path = self.Ad09_index()[0]
url = BASE_URL + path
r = self.s.get(url)
print(r.text)
return r.text
if __name__ == '__main__':
print(Ad09().get_Estimate())
request redirection的更多相关文章
- nginx指令
Directives(指令) Syntax(语法): aio on | off | threads[=pool]; Default: aio off; Context: http, server, l ...
- A JSTL primer, Part 2: Getting down to the core
In the initial article of this series, you got your first look at JSTL. We described the use of its ...
- ASP.NET-页面间的数据传递
暑假期间做项目时遇到相关问题,总结如下,与大家分享 1.通过查询字符串传递 这种方式是将参数附加在网址的后面,传递数据简单,但容易暴露,一般用于传递一些简单的数据. 例如,在Default1.aspx ...
- Springboot security cas整合方案-原理篇
前言:网络中关于Spring security整合cas的方案有很多例,对于Springboot security整合cas方案则比较少,且有些仿制下来运行也有些错误,所以博主在此篇详细的分析cas原 ...
- CDNI - RFC7336翻译
CDNI框架 摘要 本文档提出了CDNI的一个框架.框架的目的是提供对CDNI问题空间的总体描述,和描述CDN互连所需的各种组件之间的 关系.CDNI需要指定接口和机制解决诸如请求路由,分发交换元数据 ...
- [nginx] load balancing & location
一 将NGINX配置成7层load balancer,该怎么做? 参见: http://nginx.org/en/docs/http/load_balancing.html https://docs. ...
- activate mod_rewrite How To Set Up mod_rewrite for Apache on Ubuntu 14.04 Apache Rewrite url重定向功能的简单配置
https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-0 ...
- nignx的location正则匹配
原文链接:http://nginx.org/en/docs/http/ngx_http_core_module.html Syntax: location [ = | ~ | ~* | ^~ ] ur ...
- 【Azure 应用服务】App Service For Linux 部署PHP Laravel 项目,如何修改首页路径为 wwwroot\public\index.php
问题描述 参考官方文档部署 PHP Laravel 项目到App Service for Linux环境中,但是访问应用时候遇见了500 Server Error 错误. 从部署的日志中,可以明确看出 ...
随机推荐
- linux如何批量关闭进程
碰到需要杀掉某一类进程的时候,如何批量杀掉这些进程,使用awk命令是很好的选择. 代码: ps -ef|grep aaa|grep -v grep|awk '{print "kill -9 ...
- vs code使用Git
做一夜的搬运工:https://www.cnblogs.com/richard1015/p/8336429.html
- kvm虚拟机管理基础
部署 KVM 虚拟机 a.kvm 安装 环境:centos7,cpu 支持虚拟化,关闭 selinux,关闭 firewalld yum install libvirt virt-install qe ...
- git pull以及git pull --rebase
git pull的作用是将远程库中的更改代码合并到当前分支中,默认为:git fetch + git merge git fetch 的作用就相当于是从远程库中获取最新版本到本地分支,不会自动进行gi ...
- git简单提交操作
一.本地仓库操作 1.打开git命令行,先'到需要提交的目录 2.输入git init,初始化本地仓库 3.输入git add <file> 命令添加提交文件 4.输入git status ...
- CQOI2019(十二省联考)游记
CQOI2019(十二省联考)游记 Day -? 自从联赛爆炸,\(THUWC\)爆炸,\(WC\)爆炸(就没有不爆炸的)之后我已经无所畏惧... 听说是考\(4.5 h\)吗? Day -1 \(Z ...
- linux-高并发与负载均衡-lvs-功能配置介绍
百度百科: LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一. ...
- Python3中如何解决中文乱码与编码的问题
1.解决乱码问题: pyhton中内部所有编码是Unicode,中文是gbk:正常情况下,我们输出的是utf-8: 我们可以采用sys.getdefaultencoding()查看系统默认的编码: 解 ...
- C#之重写与隐藏
一 重写与隐藏区别 (1)方法重写:就是在基类中的方法用virtual关键字来标识,然后在继承类中对该类进行重写(override),这样基类中的方法已经被重写了,已经失去了功能了.当让基类的对象的引 ...
- flutter获取状态栏高度
import 'dart:ui'; MediaQueryData.fromWindow(window).padding.top 系统默认的appBar等高度 位于Dart Packages/flutt ...