Python批量獲取并保存手機(jī)號(hào)歸屬地和運(yùn)營(yíng)商的示例
從Excel讀取一組手機(jī)號(hào)碼,批量查詢?cè)撌謾C(jī)號(hào)碼的運(yùn)營(yíng)商和歸屬地,并將其追加到該記錄的末尾。
import requests
import json
import xlrd
from xlutils.copy import copy
host = 'https://cx.shouji.#/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):
# 打開文件
data = xlrd.open_workbook(path)
# 打開第一個(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('\r\n')
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)注腳本之家其它相關(guān)文章!
- Python自動(dòng)化辦公之手機(jī)號(hào)提取
- Python 批量驗(yàn)證和添加手機(jī)號(hào)碼為企業(yè)微信聯(lián)系人
- python 通過手機(jī)號(hào)識(shí)別出對(duì)應(yīng)的微信性別(實(shí)例代碼)
- Python實(shí)現(xiàn)手機(jī)號(hào)自動(dòng)判斷男女性別(實(shí)例解析)
- python實(shí)現(xiàn)的按要求生成手機(jī)號(hào)功能示例
- Python phone模塊獲取手機(jī)號(hào)歸屬地 區(qū)號(hào) 運(yùn)營(yíng)商等信息demo
相關(guān)文章
Python用正則表達(dá)式實(shí)現(xiàn)爬取古詩(shī)文網(wǎng)站信息
這篇文章主要給大家介紹了關(guān)于Python如何利用正則表達(dá)式爬取爬取古詩(shī)文網(wǎng)站信息,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-12-12
用PyInstaller把Python代碼打包成單個(gè)獨(dú)立的exe可執(zhí)行文件
這篇文章主要介紹了用PyInstaller把Python代碼打包成單個(gè)獨(dú)立的exe可執(zhí)行文件,需要的朋友可以參考下2018-05-05
Python+OpenCV圖片局部區(qū)域像素值處理改進(jìn)版詳解
這篇文章主要為大家詳細(xì)介紹了Python+OpenCV圖片局部區(qū)域像素值處理的改進(jìn)版,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01
python中matplotlib實(shí)現(xiàn)最小二乘法擬合的過程詳解
這篇文章主要給大家介紹了關(guān)于python中matplotlib實(shí)現(xiàn)最小二乘法擬合的相關(guān)資料,文中通過示例代碼詳細(xì)介紹了關(guān)于最小二乘法擬合直線和最小二乘法擬合曲線的實(shí)現(xiàn)過程,需要的朋友可以參考借鑒,下面來一起看看吧。2017-07-07
python?使用ctypes調(diào)用C/C++?dll詳情
這篇文章主要介紹了python?使用ctypes調(diào)用C/C++?dll詳情,文章首先通過導(dǎo)入ctypes模塊,加載C/C++?dll到python進(jìn)程空間展開主題相關(guān)內(nèi)容,需要的小伙伴可以參考一下2022-04-04

