Python批量獲取并保存手機(jī)號(hào)歸屬地和運(yùn)營(yíng)商的示例
從Excel讀取一組手機(jī)號(hào)碼,批量查詢(xún)?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. 如何在jsp界面中插入圖片2. ASP實(shí)現(xiàn)加法驗(yàn)證碼3. python selenium 獲取接口數(shù)據(jù)的實(shí)現(xiàn)4. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)5. 詳解JSP 內(nèi)置對(duì)象request常見(jiàn)用法6. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算7. Python matplotlib 繪制雙Y軸曲線圖的示例代碼8. jsp EL表達(dá)式詳解9. JSP servlet實(shí)現(xiàn)文件上傳下載和刪除10. springboot集成與使用Sentinel的方法
