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. 阿里前端開(kāi)發(fā)中的規(guī)范要求2. jsp實(shí)現(xiàn)登錄驗(yàn)證的過(guò)濾器3. css代碼優(yōu)化的12個(gè)技巧4. msxml3.dll 錯(cuò)誤 800c0019 系統(tǒng)錯(cuò)誤:-2146697191解決方法5. jsp EL表達(dá)式詳解6. 輕松學(xué)習(xí)XML教程7. jsp cookie+session實(shí)現(xiàn)簡(jiǎn)易自動(dòng)登錄8. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))9. xpath簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理10. 解析原生JS getComputedStyle
