python--模拟POST登陆请求(待优化)

python--模拟POST登陆请求

脚本代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests,re,sys,os
from BeautifulSoup import BeautifulSoup
import hashlib

def login(mid,id,password):
    url = 'https://merchants.dinpay.com//merchantUserLogin'
    header = {'Host':'merchants.dinpay.com',
              'Connection': 'close',
              'Content-Length': '181',
              'Cache-Control': 'max-age=0',
              'Origin': 'https://merchants.dinpay.com',
              'Upgrade-Insecure-Requests': '1',
              'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 ',
              'Content-Type': 'application/x-www-form-urlencoded',
              'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
              'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
              'Accept-Encoding': 'gzip, deflate, br',
              'Accept-Language': 'zh-CN,zh;q=0.8',
              'Cookie': 'UM_distinctid=15c39e4469d0-078856fc64a199-3c365402-1fa400-15c39e4469ed30; _qddaz=QD.tzvikv.hei039.j33u5l2z; Hm_lvt_fb3b4fe6a41548d6e25dd8367506c5a7=1495784369,1495788935,1',
            }
    data = {'savelogin': '0',
            'merchantUser.merchantId': mid,
            'merchantUser.id': id,
            'merchantUser.password': password,
            'checkNumber': '',
            'isSafeControlsValue': '0',
            'loginVersion': 'formal',
            }
    req = requests.post(url,data,header).content
    soup = BeautifulSoup(req)
    span = soup.findAll('span',id='iWantOpenShipWallet')
    mode = re.compile(r'\d+\.\d+')
    num = mode.findall(span.__str__())
    return num

if __name__ == '__main__':
    filename = sys.argv[1]
    for line in open(filename,"r"):
        list_user = line.split(',')
        mid = list_user[0]
        id = list_user[1]
        password = list_user[2]
        m = hashlib.md5()
        m.update(password)
        psw = m.hexdigest()
        num = login(mid, id, psw)
        print mid, id, password, num


<span id="iWantOpenShipWallet" style="color: red;font-weight: bold;">65.85</span>





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

徐为波

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

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

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

打赏作者

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

抵扣说明:

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

余额充值