1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import requests, xlrd, json
def get_cookie(): with open('cookie','r') as f: cookies={} for line in f.read().split(';'): name,value=line.strip().split('=',1) cookies[name]=value return cookies
def get_xls_data(): rqapi = xlrd.open_workbook('data.xls') sheet_name = rqapi.sheet_names()[0] sheet = rqapi.sheet_by_name(sheet_name) nrow = sheet.nrows return nrow,sheet
nrow,sheet = get_xls_data()
s = requests.Session()
for i in range(1, nrow): row_data = sheet.row_values(i) data = json.loads(row_data[0].replace('\'', '"')) headers = json.loads(row_data[1].replace('\'', '"'))
url = 'https://xxxxx.xxx/v2/session/?m=post' data = data headers = headers proxies={'http':'xxx.xxx.xxx.xxx:8888','https':'xxx.xxx.xxx.xxx:8888'} r=s.post(url,headers=headers,data=data, cookies=get_cookie(),proxies=proxies,verify=False) print r.json()
|