读取excel+发送请求

2021-01-21  本文已影响0人  Mracale
# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

# -*- coding:utf-8 -*-

import xlrd
import requests
import time
def __bytes__(self):
    return str(self).encode('utf-8')


def hello(rows) :
    headers = {'content-type': "application/json","Authorization":"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjY4LCJzdWIiOiIyMDAwMTEiLCJpc3MiOiIwOThmNmJjZDQ2MjFkMzczY2FkZTRlODMyNjI3YjRmNiIsImlhdCI6MTYxMTE5Njc0OSwiYXVkIjoicmVzdGFwaXVzZXIiLCJleHAiOjE2MTEyMTgzNDksIm5iZiI6MTYxMTE5Njc0OX0.n99ciA_49N7uBkOUswekmAdAEcLbg9VjQ8NCAbfWMBY"}
    url = "http://www.shengjie.club/api/customer/add"
    data = '{"address": "'+rows[5]+'","city": "'+rows[3]+'","country": "中国","customerLevel": "中","fullName": "'+rows[0]+'","industry": "其他","legalRepresentative": "'+rows[1]+'","organizationCode": "'+rows[4]+'","province": "'+rows[2]+'"}'
    data = data.encode('utf-8')
    res = requests.post(url=url,data=data,headers=headers)
    print(res.text)


x1 = xlrd.open_workbook("./888.xls")

# 2、获取sheet对象
# print(x1.sheet_names())
sheet = x1.sheet_by_index(0) # sheet索引从0开始

# print (sheet.name,sheet.nrows,sheet.ncols)
n = sheet.nrows
while n > 1:
    n -= 1
    rows = sheet.row_values(n) # 获取每一行内容
    # print(rows[0],rows[1],rows[2],rows[3],rows[4],rows[5])
    hello(rows)
    time.sleep( 5 )
print('循环结束。')

上一篇 下一篇

猜你喜欢

热点阅读