python curl实现

脚本:

#-*- coding: utf8 -*-
import xlrd
import os
import urllib
import urllib2

#忽略decode
import sys
reload(sys)
sys.setdefaultencoding('utf8')


#打开excel  
#fname = "crm_customer_detail.xlsx"
file_data = xlrd.open_workbook("crm.xlsx")
table = file_data.sheet_by_name(u'Sheet2')

#f = open('test.txt','a')
#a_list = []
#循环行数
for i in range(0,table.nrows):

    #获取每行第一列
    cus_id = table.cell(i,0).value

    #POST数据
    post_data = {"customerId":cus_id,"name":"guoxin"}
    url_post_data = urllib.urlencode(post_data)
    req_url="http://10.10.10.130:10100/domain/update-by-name"
    req = urllib2.Request(url = req_url, data = url_post_data)
    res_data = urllib2.urlopen(req)
    res = res_data.read()

    print("%s'\t'%s" % (cus_id,res))

#    url_return = os.system('/bin/curl -d "customerId=%s&name=td" "http://10.10.20.107:10800/domain/update-by-name"' % table.cell(i,0).value)

#shxrange = range(bk.nsheets)
#try:
#    sh = bk.sheet_by_name("Sheet1")
#except:
#    print "no sheet in %s named Sheet1" % fname
#获取行数
#nrows = sh.nrows
#获取列数
#ncols = sh.ncols
#print "nrows %d, ncols %d" % (nrows,ncols)
#获取第一行第一列数据 
#cell_value = sh.cell_value(1,1)
#print cell_value

#row_list = []
#获取各行数据
#for i in range(1,nrows):
 #row_data = sh.row_values(i)
 #row_list.append(row_data)
#    ptint()
View Code

 

posted @ 2017-05-05 15:55  songge1209  阅读(1196)  评论(0编辑  收藏  举报