
文章插圖
個人工作記錄使用
工作需要,經(jīng)常從接口調(diào)取數(shù)據(jù),寫個小工具,將json寫到excel表格里方便查看
用到xlwt,json,requests模塊,先上代碼,然后在介紹
a=”
excel_name=”
def make_excel():
global a
global excel_name
key=’Date’
value=https://www.520longzhigu.com/diannao/datetime.datetime.now().strftime(‘%Y-%m-%d %H:%M:%S’)
data =https://www.520longzhigu.com/diannao/{‘Authorization’:’秘鑰’,
‘Content-Type’:’json’}
data[key]=value
response=requests.get(‘url’,headers=data)
jd=json.loads(response.text)
a=(jd[‘results’])#里邊會有兩個字典,用第二個字典的鍵來查值(這個值是用字典表示的)
num = 0
workbook = xlwt.Workbook(encoding=’utf-8′)
worksheet = workbook.add_sheet(‘資源’)
for i in a:
worksheet.write(num, 0, label=i[‘ip’])#三個表示依次為行,列,值
worksheet.write(num, 1, label=i[‘isp’])
worksheet.write(num, 2, label=i[‘pro’])
num+=1
workbook.save(‘資源%s.xls’%datetime.datetime.now().strftime(‘%Y-%m-%d’))
excel_name =’資源%s.xls’%datetime.datetime.now().strftime(‘%Y-%m-%d’)
抓取輸出大概是這個樣子的,json執(zhí)行完后會以字典的方式輸出,然后弄個循環(huán)通過xlwt的用法寫進到excel表格中,最后保存在腳本當前執(zhí)行路徑下就可以了
以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問題,請您及時就醫(yī)或請專業(yè)人士給予相關(guān)指導(dǎo)!
「愛刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對您有所幫助:- 實戰(zhàn)mysql數(shù)據(jù)庫引擎 myeclipse連接mysql數(shù)據(jù)庫詳細步驟
- 講解java中常見的數(shù)據(jù)類型 java中數(shù)據(jù)類型轉(zhuǎn)換
- 精準客戶數(shù)據(jù)采集軟件介紹 數(shù)據(jù)預(yù)測軟件有哪些
- oracle11g數(shù)據(jù)庫安裝 oracle11g安裝步驟詳細
- 快速合并兩個表格為一個表格 excel兩張表數(shù)據(jù)合并
- 12月6日—12月12日 數(shù)說變化|深圳一周數(shù)據(jù)速覽
- 大數(shù)據(jù)告訴你奢侈品牌不為人知的秘密 勞力士服務(wù)地址
- 提取json格式的數(shù)據(jù) js中json字符串轉(zhuǎn)json對象的方法
- 數(shù)據(jù)庫遷移的三個步驟 mysql數(shù)據(jù)庫實時同步工具
- 數(shù)據(jù)庫性能優(yōu)化方法 數(shù)據(jù)庫怎么備份數(shù)據(jù)
