Python批量獲取并保存手機(jī)號(hào)歸屬地和運(yùn)營(yíng)商的示例
從Excel讀取一組手機(jī)號(hào)碼,批量查詢?cè)撌謾C(jī)號(hào)碼的運(yùn)營(yíng)商和歸屬地,并將其追加到該記錄的末尾。
import requestsimport jsonimport xlrdfrom xlutils.copy import copyhost = ’https://cx.shouji.360.cn/phonearea.php’# excel文件路徑file_path = 'F:temp.xlsx'# 新文件路徑new_file_path = 'F:temp(含歸屬地+運(yùn)營(yíng)商).xlsx'def query(phone_no): resp = requests.get(host, {’number’: phone_no}).content.decode(’utf-8’) js = json.loads(resp) print(js) return js[’data’]def load_excel(path): # 打開(kāi)文件 data = xlrd.open_workbook(path) # 打開(kāi)第一個(gè)sheet table = data.sheet_by_index(0) new_workbook = copy(data) new_worksheet = new_workbook.get_sheet(0) rows = table.nrows cols = table.ncols print('總行數(shù):' + str(rows)) print('總列數(shù):' + str(cols)) for row in range(rows): print('row --> ' + str(row + 1)) for col in range(cols): cel_val = table.cell(row, col).value print(cel_val) new_worksheet.write(row, col, cel_val) if row > 0: # 手機(jī)號(hào),在第一行之后的第二列 phone_no = table.cell(row, 1).value js = query(phone_no) new_worksheet.write(row, cols + 1, js[’province’] + js[’city’]) new_worksheet.write(row, cols + 2, js[’sp’]) else: new_worksheet.write(row, cols + 1, '歸屬地') new_worksheet.write(row, cols + 2, '運(yùn)營(yíng)商') print(’rn’) new_workbook.save(new_file_path)if __name__ == ’__main__’: load_excel(file_path)
以上就是Python批量獲取并保存手機(jī)號(hào)歸屬地和運(yùn)營(yíng)商的示例的詳細(xì)內(nèi)容,更多關(guān)于Python批量獲取并保存手機(jī)號(hào)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. js實(shí)現(xiàn)碰撞檢測(cè)2. 我所理解的JavaScript中的this指向3. JS實(shí)現(xiàn)前端動(dòng)態(tài)分頁(yè)碼代碼實(shí)例4. 用Spring JMS使異步消息變得簡(jiǎn)單5. PHP驗(yàn)證碼工具-Securimage6. spring acegi security 1.0.0 發(fā)布7. 關(guān)于IDEA 2020.3 多窗口視圖丟失的問(wèn)題8. javascript實(shí)現(xiàn)貪吃蛇小練習(xí)9. Vue 實(shí)現(xiàn)對(duì)quill-editor組件中的工具欄添加title10. 一文帶你徹底理解Java序列化和反序列化

網(wǎng)公網(wǎng)安備