Python批量獲取并保存手機號歸屬地和運營商的示例
更新時間:2020年10月09日 16:16:36 作者:Nemo
這篇文章主要介紹了Python批量獲取并保存手機號的歸屬地和運營商的示例,幫助大家更好的利用python處理數(shù)據(jù),感興趣的朋友可以了解下
從Excel讀取一組手機號碼,批量查詢該手機號碼的運營商和歸屬地,并將其追加到該記錄的末尾。
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(含歸屬地+運營商).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)
# 打開第一個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:
# 手機號,在第一行之后的第二列
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, "運營商")
print('\r\n')
new_workbook.save(new_file_path)
if __name__ == '__main__':
load_excel(file_path)
以上就是Python批量獲取并保存手機號歸屬地和運營商的示例的詳細內(nèi)容,更多關于Python批量獲取并保存手機號的資料請關注腳本之家其它相關文章!
相關文章
tensorflow基于Anaconda環(huán)境搭建的方法步驟
本文主要介紹了tensorflow基于Anaconda環(huán)境搭建的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-02-02
python GUI庫圖形界面開發(fā)之PyQt5窗口類QMainWindow詳細使用方法
這篇文章主要介紹了python GUI庫圖形界面開發(fā)之PyQt5窗口類QMainWindow詳細使用方法,需要的朋友可以參考下2020-02-02
python?HTTP協(xié)議相關庫requests urllib基礎學習
這篇文章主要介紹了python?HTTP協(xié)議相關庫requests urllib基礎學習,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-06-06
Python tkinter界面實現(xiàn)歷史天氣查詢的示例代碼
這篇文章主要介紹了Python tkinter界面實現(xiàn)歷史天氣查詢的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-08-08

