# 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的更多相关文章

  1. nginx指令

    Directives(指令) Syntax(语法): aio on | off | threads[=pool]; Default: aio off; Context: http, server, l ...

  2. 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  ...

  3. ASP.NET-页面间的数据传递

    暑假期间做项目时遇到相关问题,总结如下,与大家分享 1.通过查询字符串传递 这种方式是将参数附加在网址的后面,传递数据简单,但容易暴露,一般用于传递一些简单的数据. 例如,在Default1.aspx ...

  4. Springboot security cas整合方案-原理篇

    前言:网络中关于Spring security整合cas的方案有很多例,对于Springboot security整合cas方案则比较少,且有些仿制下来运行也有些错误,所以博主在此篇详细的分析cas原 ...

  5. CDNI - RFC7336翻译

    CDNI框架 摘要 本文档提出了CDNI的一个框架.框架的目的是提供对CDNI问题空间的总体描述,和描述CDN互连所需的各种组件之间的 关系.CDNI需要指定接口和机制解决诸如请求路由,分发交换元数据 ...

  6. [nginx] load balancing & location

    一 将NGINX配置成7层load balancer,该怎么做? 参见: http://nginx.org/en/docs/http/load_balancing.html https://docs. ...

  7. 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 ...

  8. nignx的location正则匹配

    原文链接:http://nginx.org/en/docs/http/ngx_http_core_module.html Syntax: location [ = | ~ | ~* | ^~ ] ur ...

  9. 【Azure 应用服务】App Service For Linux 部署PHP Laravel 项目,如何修改首页路径为 wwwroot\public\index.php

    问题描述 参考官方文档部署 PHP Laravel 项目到App Service for Linux环境中,但是访问应用时候遇见了500 Server Error 错误. 从部署的日志中,可以明确看出 ...

随机推荐

  1. Powershell-创建Module

    1.找到默认module路径,ISE启动时自动加载默认领下的Module代码. $env:PSModulePath 2.在其中一个默认路径下创建个文件夹,在文件夹下创建一个.psm1后缀文件,注意文件 ...

  2. 抽象,接口和Object类

    在面向对象的概念中, 所有的对象都是通过类来表述的, 但并不是所有的类都是用来描绘对象的, 如果一个类中么有包含足够的信息来描绘一类具体的对象, 这样的类就是抽象类. 抽象类往往用来表征对问题领域进行 ...

  3. SpringBoot中使用JNnit4(一)之Mockito的使用

    经过入门篇,可以编写出一个简单的测试用例. 这篇讲的是BDDMockito的使用. BDDMockito用于测试时进行打桩处理:通过它可以指定某个类的某个方法在什么情况下返回什么样的值. 在单元测试时 ...

  4. Centos7安装搜狗输入法.

    系统默认安装输入法管理器的是 ibus. 而搜狗使用 fcitx 1.以我们先要安装 fcitx和必要的软件包 yum -y install fcitx* yum -y install libQtWe ...

  5. 详解Tomcat的连接数和线程池

    转: https://www.cnblogs.com/kismetv/p/7806063.html#t11 前言 在使用tomcat时,经常会遇到连接数.线程数之类的配置问题,要真正理解这些概念,必须 ...

  6. React 精要面试题讲解(一) 单向数据流

    react 单向数据流概念 'react框架是怎样的数据流向?'||'react单向数据流是怎样的概念 ?' 解答这个问题之前,我们首先得知道,js框架是个怎样的概念. 框架:具备一定**编程思想** ...

  7. 正则表达式和re模块

    目录 re的元字符 字符集[ ] 转义符 分组 ( ) |符号 re下的常用方法 分组 re的元字符 import re ret = re.findall("e..a", &quo ...

  8. RPM管理工具

    linux软件包从内容上可以分为binary code和source code(二进制包和源码包) binary code无需编译,可以直接使用 source code需要经过GCC,C++编译环境编 ...

  9. SpringMVC 接受请求参数、作用域传值

    目录 原生servlet接收参数 Spring MVC最基础的参数获取 接收基本数据类型参数 方法参数列表和请求参数不一致的处理方式 接收对象引用数据类型 接收复选框这种多个同名的参数 接收obj.f ...

  10. centos6.5之phpmyadmin安装

    PhpMyAdmin 首先我们看一下百度百科,看一下phpmyadmin是做什么的. phpMyAdmin 是一个以PHP为基础,以Web-Base方式架构在网站主机上的MySQL的数据库管理工具,让 ...