python---urllib,urllib2,ssh,https请求,get请求,post请求

python—urllib,urllib2,ssh,get请求,post请求

1、代理抓包分析
在登录界面,并刷新首页获取相应的参数
这里写图片描述

这里写图片描述

这里写图片描述
这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

2、在登录界面输入账户与密码进行登录
这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

3、python脚本的源码

root@kali:~/python/dinpay# cat logindinpaypurse.py 
#!/usr/bin/python
# --*-- coding:utf-8 --*--
import ssl
import string
import urllib
import urllib2

def getlogintoken():
    urlget = "https://w.dinpay.com/memberLogin/toLogin"
    #ctl = {"ctl":"code"}
    #ctldata = urllib.urlencode(ctl)
    reqget = urllib2.Request(urlget)#构造get请求与参数

    #添加get请求的头信息
    reqget.add_header("Host","w.dinpay.com")
    reqget.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36")
    reqget.add_header("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
    reqget.add_header("Accept-Language","zh-CN,zh;q=0.8")
    reqget.add_header("Accept-Encoding","gzip, deflate, sdch, br")
    reqget.add_header("Referer","https://w.dinpay.com/memberCenter/memberIndex")
    reqget.add_header('Cookie','rememberTheUserId="gaxwb1@163.com"; JSESSIONID=42B06AB83851277CE75D335733A5C966')
    reqget.add_header("Connection","keep-alive")
    reqget.add_header("Cache-Control","max-age=0")
    reqget.add_header("Upgrade-Insecure-Requests","1")

    #使用本机进行代理抓包,查看详细的数据包
    proxy_handler = urllib2.ProxyHandler({'http': '192.168.40.36:4455'})
    opener = urllib2.build_opener(proxy_handler)
    urllib2.install_opener(opener)#

    context = ssl._create_unverified_context()#启用ssl
    resget = urllib2.urlopen(reqget,context=context)#在urllib2启用ssl字段
    resgetdata = resget.read()
    #print resgetdata
    #return resgetdata

    #对get请求的数据回包数据保存
    f = open("/root/python/dinpay/getlogintoken.txt","wb")
    f.write(resgetdata)
    f.close()

def logintoken():
        tokenlist = []
        html = open("/root/python/dinpay/getlogintoken.txt")
        t = 'var loginToken ="'
        while 1:
                x = html.readline()
                if t in x:
                        #print x
                        tokenlist.append(x[25:57])
                        #print tokenlist[0]
            return tokenlist[0]
                        break

def postcommontoken():
    url = "https://w.dinpay.com/common/getCommonToken"#请求post的url地址
        values = {"":""}
    headers = {"Host":"w.dinpay.com",
        "User-Agent" : "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
        "Accept" : "application/json, text/javascript, */*; q=0.01",
        "Accept-Language" : "zh-CN,zh;q=0.8",
        "Accept-Encoding" : "gzip, deflate, br",
        "Referer" : "https://w.dinpay.com/memberLogin/toLogin",
        "Cookie" : 'JSESSIONID=D32518287862CAAEC868827FEE81172E; rememberTheUserId="gaxwb60@163.com"',
        "Connection" : "keep-alive",
        "X-Requested-With" : "XMLHttpRequest",
        "Origin" : "https://w.dinpay.com",
        "Content-Length" : "0"}

        data = urllib.urlencode(values)#请求post表单数据
        req = urllib2.Request(url,data,headers)#请求数据)

        proxy_handler = urllib2.ProxyHandler({'http': '192.168.40.36:4455'})#抓包
        opener = urllib2.build_opener(proxy_handler)
        urllib2.install_opener(opener)#启用post请求

        context = ssl._create_unverified_context()#启用ssl
    response = urllib2.urlopen(req,context=context)#在urllib2启用ssl字段,打开请求的数据
        the_page = response.read()#读取并缓存请求到的数据

        #print the_page#打印请求到的页面

    f = open("/root/python/dinpay/postcommontoken.txt","wb")
    f.write(the_page)
    f.close()

def commontoken():
    tokenlist = []
        html = open("/root/python/dinpay/postcommontoken.txt")
        t = '"data":"'
        while 1:
                x = html.readline()
                if t in x:
                        #print x
                        tokenlist.append(x[9:41])
                        #print tokenlist[0]
            return tokenlist[0]
                        break

def getloginvalidate(logintoken,commontoken):#请求登陆业务
        url = "https://w.dinpay.com/memberLogin/getLoginValidateType"#请求post的url地址
        values = {"loginToken":logintoken,"memberId":"gaxwb60%40163.com","commonToken":commontoken}#请求的URL地址,post表单数据息

        headers = {"Host":"w.dinpay.com",
        "User-Agent" : "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
        "Accept" : "application/json, text/javascript, */*; q=0.01",
        "Accept-Language" : "zh-CN,zh;q=0.8",
        "Accept-Encoding" : "gzip, deflate, br",
    "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
        "Referer" : "https://w.dinpay.com/memberLogin/toLogin",
        "Cookie" : 'JSESSIONID=60025478F77BFB01639A567EC1BCF982; sto-id-47873=AGKCBAKMFAAA; rememberTheUserId="gaxwb60@163.com"; JSESSIONID=60025478F77BFB01639A567EC1BCF982',
        "Connection" : "keep-alive",
        "X-Requested-With" : "XMLHttpRequest",
        "Origin" : "https://w.dinpay.com",
        "Content-Length" : "115"}

        data = urllib.urlencode(values)#请求post表单数据
        req = urllib2.Request(url,data,headers)#请求数据)

        proxy_handler = urllib2.ProxyHandler({'http': '192.168.40.36:4455'})#抓包
        opener = urllib2.build_opener(proxy_handler)
        urllib2.install_opener(opener)#启用post请求

        context = ssl._create_unverified_context()#启用ssl
        response = urllib2.urlopen(req,context=context)#在urllib2启用ssl字段,打开请求的数据
        #response = urllib2.urlopen(req)#打开请求的数据
        the_page = response.read()#读取并缓存请求到的数据

        #print the_page#打印请求到的页面
    return the_page

def login(logintoken,commontoken):#请求登陆业务
    url = "https://w.dinpay.com/memberLogin/login"#请求post的url地址
    values = {"loginToken":logintoken,"memberId":"gaxwb60%40163.com","loginPassword":"qwe123456","commonToken":commontoken}#请求的URL地址,post表单数据信息

    headers = {"Host":"w.dinpay.com",
    "User-Agent" : "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
    "Accept" : "application/json, text/javascript, */*; q=0.01",
    "Accept-Language" : "zh-CN,zh;q=0.8",
    "Accept-Encoding" : "gzip, deflate, br",
    "Referer" : "https://w.dinpay.com/memberCenter/memberIndex",
    "Cookie" : 'JSESSIONID=D32518287862CAAEC868827FEE81172E; rememberTheUserId="gaxwb60@163.com"',
    "Connection" : "keep-alive",
    "X-Requested-With" : "XMLHttpRequest",
    "Origin" : "https://w.dinpay.com",
    "Content-Length" : "0"}

    data = urllib.urlencode(values)#请求post表单数据
    req = urllib2.Request(url,data,headers)#请求数据)

    proxy_handler = urllib2.ProxyHandler({'http': '192.168.40.36:4455'})#抓包
    opener = urllib2.build_opener(proxy_handler)
    urllib2.install_opener(opener)#启用post请求

    context = ssl._create_unverified_context()#启用ssl
        response = urllib2.urlopen(req,context=context)#在urllib2启用ssl字段,打开请求的数据
    #response = urllib2.urlopen(req)#打开请求的数据
    the_page = response.read()#读取并缓存请求到的数据

    print the_page#打印请求到的页面

    print "你请求到页面数据包为%d字节" %len(the_page)#计算请求到的页面数据大小

#if __name__ == "__mian__":
getlogintoken()
logintoken = logintoken()
print logintoken
postcommontoken()
commontoken = commontoken()
print commontoken
#getloginvalidate(logintoken,commontoken)

#postcommontoken()
#commontoken = commontoken()
#print commontoken
login(logintoken,commontoken)


root@kali:~/python/dinpay# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐为波

看着给就好了,学习写作有点累!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值