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